2019-12-18 16:25:01 +05:00
|
|
|
import math
|
2021-05-04 19:27:16 +05:00
|
|
|
import logging
|
2019-12-18 16:25:01 +05:00
|
|
|
|
2019-12-25 18:10:48 +05:00
|
|
|
from odoo import _, api, fields, models
|
2019-12-17 13:17:58 +05:00
|
|
|
|
2019-12-28 14:15:12 +05:00
|
|
|
from ..utils import MODULE_NAME
|
2021-04-30 16:09:43 +05:00
|
|
|
|
2021-04-30 16:09:18 +05:00
|
|
|
# from ..utils.misc import Extension, IDocument
|
2021-05-04 19:27:16 +05:00
|
|
|
_logger = logging.getLogger(__name__)
|
2019-12-17 13:17:58 +05:00
|
|
|
|
2021-05-06 18:53:42 +05:00
|
|
|
|
2021-04-30 16:09:43 +05:00
|
|
|
class ContractOrderAnnex(models.Model): # , IDocument, Extension):
|
2019-12-17 13:17:58 +05:00
|
|
|
_name = "res.partner.contract.annex"
|
2021-04-30 16:09:18 +05:00
|
|
|
_inherit = ["client_contracts.utils"]
|
2019-12-23 09:03:39 +05:00
|
|
|
_description = "Contract Annex"
|
2019-12-17 13:17:58 +05:00
|
|
|
|
2020-09-25 12:53:44 +05:00
|
|
|
name = fields.Char(
|
|
|
|
string="Name",
|
|
|
|
)
|
|
|
|
display_name = fields.Char(
|
|
|
|
compute="_compute_display_name",
|
|
|
|
)
|
|
|
|
specification_name = fields.Char(
|
|
|
|
compute="_compute_specification_name",
|
|
|
|
)
|
2020-01-17 18:59:33 +05:00
|
|
|
|
|
|
|
contract_id = fields.Many2one(
|
2020-09-25 12:53:44 +05:00
|
|
|
"res.partner.contract",
|
|
|
|
string="Contract",
|
|
|
|
readonly=True,
|
|
|
|
)
|
|
|
|
company_id = fields.Many2one(
|
2021-05-07 19:44:03 +05:00
|
|
|
comodel_name="res.company",
|
2020-09-25 12:53:44 +05:00
|
|
|
related="contract_id.company_id",
|
|
|
|
)
|
|
|
|
partner_id = fields.Many2one(
|
2021-05-07 19:44:03 +05:00
|
|
|
comodel_name="res.partner",
|
2020-09-25 12:53:44 +05:00
|
|
|
related="contract_id.partner_id",
|
2020-01-17 18:59:33 +05:00
|
|
|
)
|
2020-01-14 10:23:25 +05:00
|
|
|
order_id = fields.Many2one(
|
2021-05-07 19:44:03 +05:00
|
|
|
comodel_name="sale.order",
|
|
|
|
string="Sale order",
|
|
|
|
help="Sale order for this annex.",
|
2020-01-20 19:29:31 +05:00
|
|
|
required=True,
|
2020-01-14 10:23:25 +05:00
|
|
|
)
|
2019-12-19 19:00:46 +05:00
|
|
|
date_conclusion = fields.Date(
|
2021-05-03 23:17:54 +05:00
|
|
|
string="Signing Date",
|
2020-09-25 12:53:44 +05:00
|
|
|
default=fields.Date.today(),
|
|
|
|
)
|
|
|
|
counter = fields.Integer(
|
|
|
|
string="№",
|
2021-05-03 23:17:54 +05:00
|
|
|
help="Contract Annexes counter",
|
2020-09-25 12:53:44 +05:00
|
|
|
)
|
|
|
|
currency_id = fields.Many2one(
|
2021-05-06 18:53:42 +05:00
|
|
|
comodel_name="res.currency",
|
2021-05-03 23:17:54 +05:00
|
|
|
string="Currency",
|
|
|
|
default=lambda self: self.env.company.currency_id,
|
2019-12-19 19:00:46 +05:00
|
|
|
)
|
2019-12-17 13:17:58 +05:00
|
|
|
|
2020-09-25 12:53:44 +05:00
|
|
|
design_period = fields.Integer(
|
|
|
|
string="Design Period",
|
|
|
|
)
|
|
|
|
design_cost = fields.Monetary(
|
|
|
|
string="Design Cost",
|
|
|
|
)
|
2020-01-17 18:53:33 +05:00
|
|
|
|
2020-09-25 12:53:44 +05:00
|
|
|
design_doc_period = fields.Integer(
|
|
|
|
string="Documentation Design Period (days)",
|
|
|
|
)
|
|
|
|
design_doc_cost = fields.Monetary(
|
|
|
|
string="Documentation Design Cost",
|
|
|
|
)
|
2020-01-17 18:53:33 +05:00
|
|
|
|
2020-09-25 12:53:44 +05:00
|
|
|
delivery_address = fields.Char(
|
|
|
|
string="Delivery Address",
|
|
|
|
)
|
2020-01-17 18:53:33 +05:00
|
|
|
delivery_period = fields.Integer(string="Delivery Period (days)")
|
|
|
|
|
2020-09-25 12:53:44 +05:00
|
|
|
installation_address = fields.Char(
|
|
|
|
string="Installation Address",
|
|
|
|
)
|
|
|
|
installation_period = fields.Integer(
|
|
|
|
string="Installation Period (days)",
|
|
|
|
)
|
|
|
|
installation_cost = fields.Integer(
|
|
|
|
string="Installation Cost",
|
|
|
|
)
|
2020-01-17 18:53:33 +05:00
|
|
|
|
2020-09-25 12:53:44 +05:00
|
|
|
total_cost = fields.Monetary(
|
|
|
|
string="Total Cost",
|
|
|
|
)
|
2020-01-17 18:53:33 +05:00
|
|
|
|
2021-04-30 16:09:18 +05:00
|
|
|
payment_part_one = fields.Float(
|
|
|
|
string="Payment 1 Part (%)",
|
|
|
|
default=100,
|
|
|
|
digits="Account",
|
|
|
|
)
|
2020-09-25 12:53:44 +05:00
|
|
|
payment_part_two = fields.Float(
|
|
|
|
string="Payment 2 Part (%)",
|
2021-04-30 16:09:18 +05:00
|
|
|
digits="Account",
|
2020-09-25 12:53:44 +05:00
|
|
|
)
|
|
|
|
payment_part_three = fields.Float(
|
|
|
|
string="Payment 3 Part (%)",
|
2021-04-30 16:09:18 +05:00
|
|
|
digits="Account",
|
2020-09-25 12:53:44 +05:00
|
|
|
)
|
2020-01-17 18:53:33 +05:00
|
|
|
|
2020-01-21 16:07:57 +05:00
|
|
|
@api.depends("name")
|
|
|
|
def _compute_display_name(self):
|
|
|
|
for record in self:
|
|
|
|
record.display_name = "№{} {}".format(
|
|
|
|
record.counter or record.contract_id.contract_annex_number, record.name
|
|
|
|
)
|
2019-12-19 12:33:21 +05:00
|
|
|
|
2020-02-04 16:05:45 +05:00
|
|
|
@api.depends("contract_id", "order_id")
|
2020-01-21 16:07:57 +05:00
|
|
|
def _compute_specification_name(self):
|
|
|
|
self.specification_name = _("{name} from {date}").format(
|
|
|
|
name="{}-{}".format(self.contract_id.name, self.order_id.name),
|
|
|
|
date=self.contract_id.get_date().strftime("%d.%m.%Y"),
|
2019-12-19 12:33:21 +05:00
|
|
|
)
|
|
|
|
|
2020-01-20 19:29:31 +05:00
|
|
|
@api.onchange("order_id")
|
|
|
|
def _domain_order_id(self):
|
|
|
|
"""Using domain function because of
|
|
|
|
simple domain does not working properly because of
|
|
|
|
contract_id is still False"""
|
2019-12-19 12:33:21 +05:00
|
|
|
return {
|
|
|
|
"domain": {
|
|
|
|
"order_id": [
|
|
|
|
("partner_id", "=", self.contract_id.partner_id.id),
|
|
|
|
("contract_annex_id", "=", False),
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-21 16:07:57 +05:00
|
|
|
@api.onchange("order_id")
|
|
|
|
def _onchange_order_id(self):
|
|
|
|
contract_number = self.contract_id.name
|
|
|
|
order_number = self.order_id.name or "SO###"
|
2020-01-16 18:39:45 +05:00
|
|
|
|
2020-01-21 16:07:57 +05:00
|
|
|
self.name = "{contract}-{order}".format(
|
2020-09-25 12:53:44 +05:00
|
|
|
contract=contract_number,
|
|
|
|
order=order_number,
|
2020-01-17 17:38:40 +05:00
|
|
|
)
|
|
|
|
|
2021-05-06 18:53:42 +05:00
|
|
|
def create(self, values_list):
|
|
|
|
_logger.debug("\n\n Values: %s\n\n", values_list)
|
|
|
|
if isinstance(values_list, dict):
|
|
|
|
values_list = [values_list]
|
|
|
|
_logger.debug("\n\n Values fixed: %s\n\n", values_list)
|
|
|
|
records = super(ContractOrderAnnex, self).create(values_list)
|
|
|
|
for record in records:
|
|
|
|
# Fill annex_id to domain it in future
|
|
|
|
# record.order_id.contract_annex_id = record.id
|
|
|
|
# Counter
|
|
|
|
record.counter = record.contract_id.contract_annex_number
|
|
|
|
record.contract_id.contract_annex_number += (
|
|
|
|
1 # TODO: should I use a sequence?
|
|
|
|
)
|
|
|
|
return records
|
2019-12-18 16:25:01 +05:00
|
|
|
|
|
|
|
def action_print_form(self):
|
2019-12-30 16:02:07 +05:00
|
|
|
view = self.env.ref(
|
2020-01-14 09:47:03 +05:00
|
|
|
"{}.res_partner_wizard_print_document_view".format(MODULE_NAME)
|
2019-12-30 16:02:07 +05:00
|
|
|
)
|
2019-12-18 16:25:01 +05:00
|
|
|
return {
|
2019-12-25 13:04:26 +05:00
|
|
|
"name": _("Print Form of Contract Annex"),
|
2019-12-18 16:25:01 +05:00
|
|
|
"type": "ir.actions.act_window",
|
|
|
|
"res_model": "res.partner.contract.wizard",
|
|
|
|
"view_mode": "form",
|
|
|
|
"view_id": view.id,
|
|
|
|
"target": "new",
|
2020-07-09 01:19:51 +05:00
|
|
|
"context": {
|
|
|
|
"self_id": self.id,
|
|
|
|
"active_model": self._name,
|
2020-07-09 01:20:03 +05:00
|
|
|
"company_form": self.partner_id.company_form
|
|
|
|
if self.partner_id.is_company
|
|
|
|
else "person",
|
2020-07-09 01:19:51 +05:00
|
|
|
},
|
2019-12-18 16:25:01 +05:00
|
|
|
}
|
|
|
|
|
2020-01-17 17:13:45 +05:00
|
|
|
def get_name_by_document_template(self, document_template_id):
|
2020-08-03 16:24:44 +05:00
|
|
|
active_invoices = self.order_id.invoice_ids.filtered(
|
|
|
|
lambda r: r.state not in ("draft", "cancel")
|
|
|
|
)
|
|
|
|
bill_name = active_invoices and active_invoices[-1].number
|
2020-07-10 12:48:33 +05:00
|
|
|
|
2020-01-20 18:48:12 +05:00
|
|
|
return (
|
|
|
|
{
|
2020-07-10 12:48:33 +05:00
|
|
|
"bill": "{bill_name}",
|
2020-01-20 18:50:17 +05:00
|
|
|
"specification": "{counter} {name}",
|
|
|
|
"approval_list": "{counter}.1 {name}-1",
|
|
|
|
"act_at": "{counter}.2 {name}-2",
|
|
|
|
"act_ad": "{counter}.3 {name}-3",
|
2020-01-20 18:48:12 +05:00
|
|
|
}
|
|
|
|
.get(document_template_id.document_type_name, "Unknown")
|
2020-07-10 12:48:33 +05:00
|
|
|
.format(
|
|
|
|
counter=self.counter,
|
|
|
|
name=self.name,
|
|
|
|
bill_name=(bill_name or "Счёт отсутствует"),
|
|
|
|
)
|
2020-01-17 17:13:45 +05:00
|
|
|
)
|
|
|
|
|
2020-01-17 16:54:33 +05:00
|
|
|
def get_filename_by_document_template(self, document_template_id):
|
|
|
|
return "{type} №{name}".format(
|
2020-01-20 18:48:12 +05:00
|
|
|
type=_(
|
|
|
|
dict(document_template_id._fields["document_type"].selection).get(
|
|
|
|
document_template_id.document_type
|
|
|
|
)
|
|
|
|
),
|
2020-01-17 16:54:33 +05:00
|
|
|
name={
|
2020-01-20 18:50:17 +05:00
|
|
|
"bill": "{counter} {type} {name}",
|
|
|
|
"specification": "{counter} {type} {name}",
|
|
|
|
"approval_list": "{counter}.1 {type} {name}-1",
|
|
|
|
"act_at": "{counter}.2 {type} {name}-2",
|
|
|
|
"act_ad": "{counter}.3 {type} {name}-3",
|
2020-01-20 18:48:12 +05:00
|
|
|
}
|
2020-03-20 11:07:11 +05:00
|
|
|
.get(document_template_id.document_type_name, "Unknown")
|
2020-01-20 18:48:12 +05:00
|
|
|
.format(
|
2020-01-20 18:50:17 +05:00
|
|
|
counter=self.counter,
|
2020-01-20 18:48:12 +05:00
|
|
|
type=_(
|
|
|
|
dict(
|
|
|
|
document_template_id._fields["document_type_name"].selection
|
|
|
|
).get(document_template_id.document_type_name)
|
|
|
|
),
|
2020-01-17 16:54:33 +05:00
|
|
|
name=self.name,
|
2020-01-20 18:48:12 +05:00
|
|
|
),
|
2020-01-17 16:54:33 +05:00
|
|
|
)
|
|
|
|
|
2019-12-18 16:25:01 +05:00
|
|
|
def modf(self, arg):
|
|
|
|
"""Math.modf function for using in XML ir.action.server code
|
|
|
|
Uses in data/fields_default.xml
|
|
|
|
"""
|
|
|
|
return math.modf(arg)
|