|
1 |
| -from odoo import _, models, fields, api |
2 |
| -from odoo.exceptions import ValidationError |
3 |
| -import logging |
4 |
| - |
5 |
| -_logger = logging.getLogger(__name__) |
| 1 | +from odoo import models, fields, api |
6 | 2 |
|
7 | 3 |
|
8 | 4 | class AccountMove(models.Model):
|
9 | 5 | _inherit = 'account.move'
|
10 | 6 |
|
11 |
| - student_id = fields.Many2one('res.partner', string='Alumno', domain="[('parent_id', '=', partner_id), ('partner_type', '=', 'student')]") |
| 7 | + student_ids = fields.Many2many('res.partner', compute="_compute_student_ids") |
| 8 | + partner_shipping_id = fields.Many2one(domain="[('id', 'in', student_ids), ('partner_type', '=', 'student')]") |
12 | 9 |
|
13 |
| - @api.constrains('student_id') |
14 |
| - def _check_student(self): |
15 |
| - invoices_wo_student = self.filtered(lambda x: x.type in ["out_invoice", "out_refund"] and not x.student_id) |
16 |
| - if invoices_wo_student: |
17 |
| - msg = _("Las facturas de clientes y notas de debito debe tener asociado siempre un alumno") |
18 |
| - if len(invoices_wo_student) > 1: |
19 |
| - msg += ".\n" + _("Los siguientes documentos no cumplen esa condición:") + "\n\n - %s" % '\n - '.join(invoices_wo_student.mapped('display_name')) |
20 |
| - raise ValidationError(msg) |
| 10 | + @api.depends('partner_id') |
| 11 | + def _compute_student_ids(self): |
| 12 | + for rec in self: |
| 13 | + if rec.partner_id: |
| 14 | + student_ids = self.env['res.partner.link'].search( |
| 15 | + [('partner_id', '=', rec.partner_id.id), ('role_ids', 'in', self.env.ref('academic.paying_role').id)] |
| 16 | + ).mapped('student_id.id') |
| 17 | + rec.student_ids = [(6, 0, student_ids)] |
| 18 | + else: |
| 19 | + rec.student_ids = [(5, 0, 0)] |
0 commit comments