diff --git a/academic/i18n/es.po b/academic/i18n/es.po index 3afc9135..e16a2f3f 100644 --- a/academic/i18n/es.po +++ b/academic/i18n/es.po @@ -1275,3 +1275,27 @@ msgstr "" #: model_terms:ir.ui.view,arch_db:academic.view_academic_group_filter msgid "Archived" msgstr "Archivado" + +#. module: academic +#: model:ir.model.fields,field_description:academic.field_account_bank_statement_line__require_student_on_invoices +#: model:ir.model.fields,field_description:academic.field_account_move__require_student_on_invoices +#: model:ir.model.fields,field_description:academic.field_account_payment__require_student_on_invoices +#: model:ir.model.fields,field_description:academic.field_res_company__require_student_on_invoices +msgid "Require Student On Invoices" +msgstr "Requerir Estudiantes en Facturas" + +#. module: academic +#: model_terms:ir.ui.view,arch_db:academic.academic_view_move_form +msgid "Warning: This invoice is not associated with any student" +msgstr "Precaución: Esta factura no está asociada a ningún estudiante" + +#. module: academic +#. odoo-python +#: code:addons/academic/models/res_company.py:0 +#, python-format +msgid "" +"You cannot mark require student on invoices if there are already invoices " +"without students." +msgstr "" +"No puedes marcar 'requerir estudiante' en las facturas si ya existen facturas " +"sin estudiantes." diff --git a/academic/models/account_move.py b/academic/models/account_move.py index 52a1929d..0f928685 100644 --- a/academic/models/account_move.py +++ b/academic/models/account_move.py @@ -1,4 +1,4 @@ -from odoo import api, fields, models +from odoo import _, api, fields, models from odoo.exceptions import ValidationError @@ -10,6 +10,7 @@ class AccountMove(models.Model): student_id = fields.Many2one( "res.partner", domain="[('id', 'in', student_ids), ('partner_type', '=', 'student')]", index=True ) + require_student_on_invoices = fields.Boolean(related="company_id.require_student_on_invoices") @api.constrains("student_id", "move_type") def _check_student(self): @@ -17,16 +18,19 @@ def _check_student(self): # desactivamos el chequeo cuando se hace la instalación if self.env.context.get("install_mode"): return True - invoices_wo_student = self.filtered(lambda x: x.move_type in ["out_invoice", "out_refund"] and not x.student_id) - if invoices_wo_student: - msg = self.env._("Las facturas de clientes y notas de debito debe tener asociado siempre un alumno.") - if len(invoices_wo_student) > 1: - msg += ( - ".\n" - + self.env._("Los siguientes documentos no cumplen esa condición:") - + "\n\n - %s" % "\n - ".join(invoices_wo_student.mapped("display_name")) - ) - raise ValidationError(msg) + if self.filtered("require_student_on_invoices"): + invoices_wo_student = self.filtered( + lambda x: x.move_type in ["out_invoice", "out_refund"] and not x.student_id + ) + if invoices_wo_student: + msg = _("Las facturas de clientes y notas de debito debe tener asociado siempre un alumno.") + if len(invoices_wo_student) > 1: + msg += ( + ".\n" + + _("Los siguientes documentos no cumplen esa condición:") + + "\n\n - %s" % "\n - ".join(invoices_wo_student.mapped("display_name")) + ) + raise ValidationError(msg) @api.depends("partner_id") def _compute_student_ids(self): diff --git a/academic/models/res_company.py b/academic/models/res_company.py index a5f2aedc..f2e92a6d 100644 --- a/academic/models/res_company.py +++ b/academic/models/res_company.py @@ -2,7 +2,8 @@ # For copyright and license notices, see __manifest__.py file in module root # directory ############################################################################## -from odoo import fields, models +from odoo import api, fields, models +from odoo.exceptions import UserError class ResCompany(models.Model): @@ -15,3 +16,23 @@ class ResCompany(models.Model): ) study_plan_id = fields.Many2one(comodel_name="academic.study.plan", string="Plan de Estudio") family_required = fields.Boolean() + require_student_on_invoices = fields.Boolean(default=True) + + @api.constrains("require_student_on_invoices") + def _check_invoices_with_student(self): + cia_require_students = self.filtered("require_student_on_invoices") + if cia_require_students: + invoices = self.env["account.move"].search( + [ + ("company_id", "in", cia_require_students.ids), + ("move_type", "in", ["out_invoice", "out_refund"]), + ("student_id", "=", False), + ], + limit=1, + ) + if invoices: + raise UserError( + self.env._( + "You cannot mark require student on invoices if there are already invoices without students." + ) + ) diff --git a/academic/views/account_move_views.xml b/academic/views/account_move_views.xml index 32adfcd9..265713f7 100644 --- a/academic/views/account_move_views.xml +++ b/academic/views/account_move_views.xml @@ -24,6 +24,12 @@ 1 + + + + diff --git a/academic/views/res_company_views.xml b/academic/views/res_company_views.xml index 4d0dc620..b13f98b0 100644 --- a/academic/views/res_company_views.xml +++ b/academic/views/res_company_views.xml @@ -34,6 +34,7 @@
+