Skip to content

[FW][IMP] academic: include sequence in student link mapping for invoice … #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions academic/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,30 @@ def _compute_student_links(self):
for link in rec.parent_id.student_link_ids:
existing_link = rec.student_link_ids.filtered(lambda l: l.partner_id == link.partner_id)
if existing_link:
<<<<<<< HEAD
existing_link.write(
{
"relationship_id": link.relationship_id.id,
"note": link.note,
"role_ids": [(6, 0, link.role_ids.ids)],
}
)
||||||| parent of 5b4599d (temp)
existing_link.write({
'relationship_id': link.relationship_id.id,
'note': link.note,
'role_ids': [(6, 0, link.role_ids.ids)],
})
=======
existing_link.write({
'relationship_id': link.relationship_id.id,
'note': link.note,
'role_ids': [(6, 0, link.role_ids.ids)],
'sequence': link.sequence,
})
>>>>>>> 5b4599d (temp)
else:
<<<<<<< HEAD
commands.append(
(
0,
Expand All @@ -122,6 +138,24 @@ def _compute_student_links(self):
)
)
parent_partner_ids = rec.parent_id.student_link_ids.mapped("partner_id")
||||||| parent of 5b4599d (temp)
commands.append((0, 0, {
'partner_id': link.partner_id.id,
'relationship_id': link.relationship_id.id,
'note': link.note,
'role_ids': [(6, 0, link.role_ids.ids)],
}))
parent_partner_ids = rec.parent_id.student_link_ids.mapped('partner_id')
=======
commands.append((0, 0, {
'partner_id': link.partner_id.id,
'relationship_id': link.relationship_id.id,
'note': link.note,
'role_ids': [(6, 0, link.role_ids.ids)],
'sequence': link.sequence,
}))
parent_partner_ids = rec.parent_id.student_link_ids.mapped('partner_id')
>>>>>>> 5b4599d (temp)
obsolete_links = rec.student_link_ids.filtered(lambda l: l.partner_id not in parent_partner_ids)
commands += [(2, link.id) for link in obsolete_links]
if commands:
Expand Down
64 changes: 64 additions & 0 deletions academic/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import api, models, fields, _


class SaleOrder(models.Model):

_inherit = 'sale.order'

partner_id = fields.Many2one(domain="[('type', '!=', 'private'), ('company_id', 'in', (False, company_id)), ('partner_type', '=', 'student')]")
partner_invoice_ids = fields.Many2many('res.partner', compute='_compute_partner_invoice')

# dejamos solo depends a partner_id para que si cambia algo de la asignación no se re-calculen todas las ventas existentes
@api.depends('partner_id')
def _compute_partner_invoice(self):
orders = self.filtered('partner_id')
for rec in orders:
student_links = rec.partner_id.student_link_ids.filtered(
lambda x: self.env.ref('academic.paying_role') in x.role_ids
).sorted('sequence')
rec.partner_invoice_ids = student_links.mapped('partner_id')
(self - orders).partner_invoice_ids = False

@api.depends('partner_invoice_ids')
def _compute_partner_invoice_id(self):
# si bien en el dominio solo permitimos estudiantes, para no romper demo data de odoo ni tests, si no es un estudiante
# dejamos compute by super
students_orders = self.filtered(lambda x: x.partner_id.partner_type == 'student')
for order in students_orders:
order.partner_invoice_id = order.partner_invoice_ids._origin[:1]
super(SaleOrder, self - students_orders)._compute_partner_invoice_id()

def _prepare_invoice(self):
res = super()._prepare_invoice()
res["student_id"] = self.partner_id.id
return res

def action_confirm(self):
for rec in self:
rec.message_subscribe([
payment_responsible.id
for payment_responsible in rec.partner_invoice_id | rec.partner_invoice_ids
if payment_responsible not in rec.sudo().message_partner_ids
])
return super().action_confirm()

def _message_get_default_recipients(self):
""" Por defecto las plantillas mandan a partner_id pero para nosotros el partners es el estudiante.
Cambiamos plantillas para que usen el campo "use_default_to" y luego cae en este método de python donde
podemos ir mejorando a medida que nos pidan y modificar la logica de recipients.
Por ahora lo mandamos solo al partner de facturación si está definido
"""
default_recipients = super()._message_get_default_recipients()
for record in self:
payment_responsible = record.partner_invoice_id | record.partner_invoice_ids
if payment_responsible:
default_recipients[record.id] = {
'email_cc': False,
'email_to': False,
'partner_ids': payment_responsible.ids,
}
return default_recipients
Loading