96 lines
3.5 KiB
Python
96 lines
3.5 KiB
Python
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)
|