2021-05-11 23:58:05 +05:00
|
|
|
from odoo import api, fields, models, _
|
2019-12-18 17:18:00 +05:00
|
|
|
|
2019-12-28 14:15:12 +05:00
|
|
|
from ..utils import MODULE_NAME
|
|
|
|
|
2019-12-18 17:18:00 +05:00
|
|
|
|
|
|
|
class SaleOrder(models.Model):
|
2019-12-19 10:55:25 +05:00
|
|
|
_inherit = "sale.order"
|
2019-12-18 17:18:00 +05:00
|
|
|
|
2021-05-03 23:17:54 +05:00
|
|
|
# TODO: exists original field "commitment_date".
|
2020-09-25 12:53:44 +05:00
|
|
|
delivery_time = fields.Integer(
|
|
|
|
string="Delivery Time",
|
|
|
|
default=45,
|
|
|
|
)
|
2019-12-19 10:55:25 +05:00
|
|
|
contract_annex_id = fields.Many2one(
|
2021-05-07 19:44:03 +05:00
|
|
|
comodel_name="res.partner.contract.annex",
|
2020-09-25 12:53:44 +05:00
|
|
|
string="Contract Annex",
|
2021-05-07 19:44:03 +05:00
|
|
|
compute="get_contract_annex_id",
|
2019-12-18 17:18:00 +05:00
|
|
|
)
|
2021-05-07 19:44:03 +05:00
|
|
|
contract_annex_ids = fields.One2many(
|
|
|
|
comodel_name="res.partner.contract.annex",
|
|
|
|
inverse_name="order_id",
|
|
|
|
string="Annex for this Sale order",
|
|
|
|
help="Technical field for binding with contract annex\n"
|
|
|
|
"In form this link showed in 'contract_annex_id' field.",
|
|
|
|
)
|
|
|
|
|
2021-05-03 23:17:54 +05:00
|
|
|
# Extend default field for showing payment terms created by this module only.
|
2019-12-18 17:18:00 +05:00
|
|
|
payment_term_id = fields.Many2one(
|
2021-05-07 19:44:03 +05:00
|
|
|
comodel_name="account.payment.term",
|
2019-12-19 10:55:25 +05:00
|
|
|
domain=lambda self: [("id", "in", self._get_payment_terms())],
|
2019-12-18 17:18:00 +05:00
|
|
|
)
|
|
|
|
|
|
|
|
def _get_payment_terms(self):
|
2021-05-07 19:44:03 +05:00
|
|
|
terms = [
|
|
|
|
self.env.ref("{}.{}".format(MODULE_NAME, external_id)).id
|
2019-12-30 10:36:57 +05:00
|
|
|
for external_id in (
|
|
|
|
"payment_term_prepaid",
|
|
|
|
"payment_term_postpayment",
|
|
|
|
"payment_term_partial_2",
|
|
|
|
"payment_term_partial_3",
|
|
|
|
)
|
2021-05-07 19:44:03 +05:00
|
|
|
]
|
|
|
|
return terms
|
|
|
|
|
|
|
|
@api.onchange("contract_annex_ids")
|
|
|
|
def get_contract_annex_id(self):
|
|
|
|
if self.contract_annex_ids:
|
|
|
|
self.contract_annex_id = self.contract_annex_ids[0].id
|
|
|
|
else:
|
|
|
|
self.contract_annex_id = False
|
2021-05-11 23:58:05 +05:00
|
|
|
|
|
|
|
def action_print_form(self):
|
|
|
|
self.ensure_one()
|
|
|
|
view = self.env.ref(
|
|
|
|
"{}.res_partner_wizard_print_document_view".format(MODULE_NAME)
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
"name": _("Print Form of Contract"),
|
|
|
|
"type": "ir.actions.act_window",
|
|
|
|
"res_model": "res.partner.contract.wizard",
|
|
|
|
"view_mode": "form",
|
|
|
|
"view_id": view.id,
|
|
|
|
"target": "new",
|
|
|
|
"context": {
|
|
|
|
"self_id": self.id,
|
|
|
|
"active_model": self._name,
|
|
|
|
"company_form": self.partner_id.company_form
|
|
|
|
if self.partner_id.is_company
|
|
|
|
else "person",
|
|
|
|
"attachment_model": "sale.order",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
def get_filename_by_document_template(self, document_template_id):
|
|
|
|
self.ensure_one()
|
|
|
|
return "{doc_type} {number} {from_} {date}".format(
|
|
|
|
doc_type=_("Offer"),
|
|
|
|
number=self.name,
|
|
|
|
from_=_("from"),
|
|
|
|
date=self.date_order.strftime("%d.%m.%Y"),
|
|
|
|
)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _t(arg):
|
|
|
|
"""Uses in xml action (data/fields_default)
|
|
|
|
Arguments:
|
|
|
|
arg {str} -- String to translate
|
|
|
|
"""
|
|
|
|
return _(arg)
|