diff --git a/contract.py b/contract.py new file mode 100644 index 0000000..1389dd0 --- /dev/null +++ b/contract.py @@ -0,0 +1,95 @@ +from trytond.pool import Pool, PoolMeta +from trytond.model import ( + ModelSQL, ModelView, Workflow, fields) +from trytond.pyson import Eval, If, Bool +from trytond.modules.company.model import set_employee +from trytond.exceptions import UserError +from trytond.transaction import Transaction +from trytond.wizard import ( + Button, StateAction, StateTransition, StateView, Wizard) + +from trytond.modules.currency.fields import Monetary +from trytond.modules.product import price_digits + +import datetime +from datetime import timedelta + + +class Contract(ModelSQL, ModelView): + 'Contracts' + __name__ = 'optical_equipment.contract' + + company = fields.Many2One( + 'company.company', "Company", readonly=True, required=True, select=True, + states={ + 'readonly': (Eval('state') != 'draft') | Eval('party', True), + },help="Make the subscription belong to the company.") + number = fields.Char( + "Number", readonly=True, select=True, + help="The main identification of the subscription.") + reference = fields.Char( + "Reference", select=True, + help="The identification of an external origin.") + description = fields.Char("Description", + states={ + 'readonly': Eval('state') != 'draft', + }) + party = fields.Many2One( + 'party.party', "Party", readonly=True, required=True, + help="The party who subscribes.") + contact = fields.Many2One('party.contact_mechanism', "Contact", readonly=True) + invoice_address = fields.Many2One('party.address', 'Invoice Address', readonly=True, + required=True, domain=[('party', '=', Eval('party'))]) + start_date = fields.Date("Start Date", readonly=True, required=False,) + end_date = fields.Date( + "End Date", readonly=True, + domain=['OR', + ('end_date', '>=', If( + Bool(Eval('start_date')), + Eval('start_date', datetime.date.min), + datetime.date.min)), + ('end_date', '=', None), + ], + states={ + 'readonly': Eval('state') != 'draft', + } + ) + maintenance_services = fields.Many2Many('optical_equipment_maintenance.service-equipment.contract', + 'contract', 'maintenance_services', "Prorogues") + state = fields.Selection([ + ('draft', "Draft"), + ('quotation', "Quotation"), + ('running', "Running"), + ('closed', "Closed"), + ('cancelled', "Cancelled"), + ], "State", readonly=True, required=False, sort=False, + help="The current state of the subscription.") + + + @classmethod + def __setup__(cls): + super(Contract, cls).__setup__() + + @staticmethod + def default_company(): + return Transaction().context.get('company') + + @staticmethod + def default_state(): + return 'draft' + + + +class ContractMaintenanceServices(ModelSQL): + 'Contract - Maintenance Services' + __name__ = 'optical_equipment_maintenance.service-equipment.contract' + + maintenance_services = fields.Many2One('optical_equipment_maintenance.service', "Maintenance Service", select=True) + contract = fields.Many2One('optical_equipment.contract', "Contract") + +class ContractEquipment(ModelSQL): + 'Optical Equipment - Contract' + __name__ = 'optical_equipment.contract-optical_equipment.equipment' + + equipment = fields.Many2One('optical_equipment.equipment', 'Equipment', select=True) + contract = fields.Many2One('optical_equipment.contract', 'Contract', select=True) diff --git a/contract.xml b/contract.xml new file mode 100644 index 0000000..76c81f9 --- /dev/null +++ b/contract.xml @@ -0,0 +1,119 @@ + + + + + optical_equipment.contract + form + contract_form + + + optical_equipment.contract + tree + contract_list + + + Contracts + optical_equipment.contract + + + + + + + + + + + + + Draft + + + + + + + Quotation + + + + + + + Running + + + + + + Closed + + + + + + All + + + + + + + + + diff --git a/maintenance_line_form.xml b/maintenance_line_form.xml new file mode 100644 index 0000000..187ed83 --- /dev/null +++ b/maintenance_line_form.xml @@ -0,0 +1,11 @@ + + +
+