docx_report_generation/models/account_invoice.py

68 lines
2.3 KiB
Python
Raw Normal View History

from odoo import models, _
from odoo.exceptions import UserError
from ..utils import MODULE_NAME
class AccountInvoice(models.Model):
_inherit = "account.move"
@staticmethod
def check_contract_presence(sale_order_ids):
error_message = ""
if any(not so.contract_annex_id.contract_id for so in sale_order_ids):
error_message = _("There is a Sale order without binding contract.")
2021-04-30 16:09:43 +05:00
if any(not so.contract_annex_id for so in sale_order_ids):
error_message = _("There is a Sale order without annex.")
if error_message:
raise UserError(error_message)
def action_invoice_print(self):
2021-04-30 16:09:43 +05:00
"""
for so in self.env["sale.order"].search([]):
if self.id in so.invoice_ids.ids:
order = so
break
else:
return super().action_invoice_print()
if not order.contract_annex_id or not order.contract_annex_id.contract_id:
raise UserError(
_(
"There is no binding contract. It is necessary to link the order with the annex to the contract."
)
)
self.sent = True
2021-04-30 16:09:43 +05:00
"""
2021-04-30 16:09:43 +05:00
sale_orders_ids = self.env["sale.order"].search(
[("invoice_ids", "in", self.ids)]
)
if not sale_orders_ids:
return super().action_invoice_print()
self.check_contract_presence(sale_orders_ids)
2021-04-30 16:09:43 +05:00
self.filtered(lambda inv: not inv.is_move_sent).write({"is_move_sent": True})
view = self.env.ref(
"{}.res_partner_wizard_print_document_view".format(MODULE_NAME)
)
2021-04-29 23:32:23 +05:00
# annex = order.contract_annex_id
return {
"name": _("Print Form of Contract Annex"),
"type": "ir.actions.act_window",
"res_model": "res.partner.contract.wizard",
"view_mode": "form",
"view_id": view.id,
"target": "new",
"context": {
2021-04-29 23:32:23 +05:00
# "self_id": annex.id,
"active_ids": self.ids,
"active_model": "res.partner.contract.annex",
2021-04-29 23:32:23 +05:00
# "company_form": annex.partner_id.company_form
# if annex.partner_id.is_company
# else "person",
2020-03-20 11:07:11 +05:00
"attachment_model": self._name,
2020-03-20 11:08:52 +05:00
"attachment_res_id": self.id,
},
}