Skip to content

Commit 8c6923f

Browse files
committed
[IMP] academic: boolean to require student in invoices
X-original-commit: 1a16c36
1 parent a6ec33e commit 8c6923f

File tree

5 files changed

+73
-11
lines changed

5 files changed

+73
-11
lines changed

academic/i18n/es.po

+30
Original file line numberDiff line numberDiff line change
@@ -1288,3 +1288,33 @@ msgstr "asignatura"
12881288
#: model:ir.model.fields,help:academic.field_res_users__disabled_person
12891289
msgid "¿Alumno/a con Dificultades de aprendizaje?"
12901290
msgstr ""
1291+
1292+
#. module: academic
1293+
#. odoo-python
1294+
#: code:addons/academic/models/academic_group.py:0
1295+
msgid "Year: %s"
1296+
msgstr ""
1297+
1298+
#. module: academic
1299+
#: model:ir.model.fields,field_description:academic.field_account_bank_statement_line__require_student_on_invoices
1300+
#: model:ir.model.fields,field_description:academic.field_account_move__require_student_on_invoices
1301+
#: model:ir.model.fields,field_description:academic.field_account_payment__require_student_on_invoices
1302+
#: model:ir.model.fields,field_description:academic.field_res_company__require_student_on_invoices
1303+
msgid "Require Student On Invoices"
1304+
msgstr "Requerir Estudiantes en Facturas"
1305+
1306+
#. module: academic
1307+
#: model_terms:ir.ui.view,arch_db:academic.academic_view_move_form
1308+
msgid "Warning: This invoice is not associated with any student"
1309+
msgstr "Precaución: Esta factura no está asociada a ningún estudiante"
1310+
1311+
#. module: academic
1312+
#. odoo-python
1313+
#: code:addons/academic/models/res_company.py:0
1314+
#, python-format
1315+
msgid ""
1316+
"You cannot mark require student on invoices if there are already invoices "
1317+
"without students."
1318+
msgstr ""
1319+
"No puedes marcar 'requerir estudiante' en las facturas si ya existen facturas "
1320+
"sin estudiantes."

academic/models/account_move.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,27 @@ class AccountMove(models.Model):
1010
student_id = fields.Many2one(
1111
"res.partner", domain="[('id', 'in', student_ids), ('partner_type', '=', 'student')]", index=True
1212
)
13+
require_student_on_invoices = fields.Boolean(related="company_id.require_student_on_invoices")
1314

1415
@api.constrains("student_id", "move_type")
1516
def _check_student(self):
1617
# Está saltando warning en runbot por esta constrains ya que hay facturas sin estudiante, por lo tanto
1718
# desactivamos el chequeo cuando se hace la instalación
1819
if self.env.context.get("install_mode"):
1920
return True
20-
invoices_wo_student = self.filtered(lambda x: x.move_type in ["out_invoice", "out_refund"] and not x.student_id)
21-
if invoices_wo_student:
22-
msg = self.env._("Las facturas de clientes y notas de debito debe tener asociado siempre un alumno.")
23-
if len(invoices_wo_student) > 1:
24-
msg += (
25-
".\n"
26-
+ self.env._("Los siguientes documentos no cumplen esa condición:")
27-
+ "\n\n - %s" % "\n - ".join(invoices_wo_student.mapped("display_name"))
28-
)
29-
raise ValidationError(msg)
21+
if self.filtered("require_student_on_invoices"):
22+
invoices_wo_student = self.filtered(
23+
lambda x: x.move_type in ["out_invoice", "out_refund"] and not x.student_id
24+
)
25+
if invoices_wo_student:
26+
msg = self.env._("Las facturas de clientes y notas de debito debe tener asociado siempre un alumno.")
27+
if len(invoices_wo_student) > 1:
28+
msg += (
29+
".\n"
30+
+ self.env._("Los siguientes documentos no cumplen esa condición:")
31+
+ "\n\n - %s" % "\n - ".join(invoices_wo_student.mapped("display_name"))
32+
)
33+
raise ValidationError(msg)
3034

3135
@api.depends("partner_id")
3236
def _compute_student_ids(self):

academic/models/res_company.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# For copyright and license notices, see __manifest__.py file in module root
33
# directory
44
##############################################################################
5-
from odoo import fields, models
5+
from odoo import api, fields, models
6+
from odoo.exceptions import UserError
67

78

89
class ResCompany(models.Model):
@@ -15,3 +16,23 @@ class ResCompany(models.Model):
1516
)
1617
study_plan_id = fields.Many2one(comodel_name="academic.study.plan", string="Plan de Estudio")
1718
family_required = fields.Boolean()
19+
require_student_on_invoices = fields.Boolean(default=True)
20+
21+
@api.constrains("require_student_on_invoices")
22+
def _check_invoices_with_student(self):
23+
cia_require_students = self.filtered("require_student_on_invoices")
24+
if cia_require_students:
25+
invoices = self.env["account.move"].search(
26+
[
27+
("company_id", "in", cia_require_students.ids),
28+
("move_type", "in", ["out_invoice", "out_refund"]),
29+
("student_id", "=", False),
30+
],
31+
limit=1,
32+
)
33+
if invoices:
34+
raise UserError(
35+
self.env._(
36+
"You cannot mark require student on invoices if there are already invoices without students."
37+
)
38+
)

academic/views/account_move_views.xml

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
<field name="partner_shipping_id" position="attributes">
2525
<attribute name="invisible">1</attribute>
2626
</field>
27+
<xpath expr="//sheet" position="before">
28+
<field name="require_student_on_invoices" invisible="1"/>
29+
<div class="alert alert-warning oe_edit_only" role="alert" invisible="student_id or not require_student_on_invoices">
30+
Warning: This invoice is not associated with any student
31+
</div>
32+
</xpath>
2733
</field>
2834
</record>
2935
<record id="academic_view_account_invoice_filter" model="ir.ui.view">

academic/views/res_company_views.xml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<div class="o_address_format" position='after'>
3535
<field name="study_plan_id"/>
3636
<field name="family_required"/>
37+
<field name="require_student_on_invoices"/>
3738
</div>
3839
</field>
3940
</record>

0 commit comments

Comments
 (0)