docx_report_generation/models/res_partner_contract_annex.py

79 lines
2.4 KiB
Python
Raw Normal View History

import math
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
2019-12-17 13:17:58 +05:00
class ContractOrderAnnex(models.Model):
_name = "res.partner.contract.annex"
2019-12-23 09:03:39 +05:00
_description = "Contract Annex"
2019-12-17 13:17:58 +05:00
name = fields.Char(string="Name", help="The Number of Annex")
order_id = fields.Many2one("sale.order", string="Order", required=True,)
2019-12-17 13:17:58 +05:00
contract_id = fields.Many2one(
"res.partner.contract", string="Contract", readonly=True,
2019-12-17 13:17:58 +05:00
)
2019-12-19 19:00:46 +05:00
date_conclusion = fields.Date(
string="Conclusion Date", default=fields.Date.today(),
)
2019-12-28 13:11:27 +05:00
prepaid_expense = fields.Float(string="Prepaid Expense", default=0)
2019-12-19 19:00:46 +05:00
delivery_time = fields.Integer(related="order_id.delivery_time", readonly=True,)
payment_term = fields.Many2one(
"account.payment.term", related="order_id.payment_term_id", readonly=True,
)
2019-12-17 13:17:58 +05:00
@api.onchange("contract_id")
def _onchange_contract_id(self):
# Compute name if there is no custom name
contract_number = self.contract_id.name
annex_number = self.contract_id.contract_annex_number
self.name = "{contract}--{annex}".format(
contract=contract_number, annex=annex_number
)
# Compute domain for order_id because of bug with
# not working correctly domain in model
return {
"domain": {
"order_id": [
("partner_id", "=", self.contract_id.partner_id.id),
("contract_annex_id", "=", False),
]
}
}
2019-12-17 13:17:58 +05:00
@api.model
def create(self, values):
record = super().create(values)
# Fill annex_id to domain it in future
record.order_id.contract_annex_id = record.id
2019-12-17 13:17:58 +05:00
# Add counter
record.contract_id.contract_annex_number += 1
2019-12-17 13:17:58 +05:00
return record
@api.multi
def action_print_form(self):
2019-12-30 16:02:07 +05:00
view = self.env.ref(
"{}.res_partner_wizard_print_annex_view".format(MODULE_NAME)
)
return {
2019-12-25 13:04:26 +05:00
"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": {"self_id": self.id},
}
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)