Skip to content
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

[IMP] academic: boolean to require student in invoices #215

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
24 changes: 24 additions & 0 deletions academic/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -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."
26 changes: 15 additions & 11 deletions academic/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


Expand All @@ -10,23 +10,27 @@ 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):
# Está saltando warning en runbot por esta constrains ya que hay facturas sin estudiante, por lo tanto
# 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):
Expand Down
23 changes: 22 additions & 1 deletion academic/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."
)
)
6 changes: 6 additions & 0 deletions academic/views/account_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<field name="partner_shipping_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<xpath expr="//sheet" position="before">
<field name="require_student_on_invoices" invisible="1"/>
<div class="alert alert-warning oe_edit_only" role="alert" invisible="student_id or not require_student_on_invoices">
Warning: This invoice is not associated with any student
</div>
</xpath>
</field>
</record>
<record id="academic_view_account_invoice_filter" model="ir.ui.view">
Expand Down
1 change: 1 addition & 0 deletions academic/views/res_company_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<div class="o_address_format" position='after'>
<field name="study_plan_id"/>
<field name="family_required"/>
<field name="require_student_on_invoices"/>
</div>
</field>
</record>
Expand Down