correction to module contracts
This commit is contained in:
parent
86b6bef61d
commit
8cd2cf17bf
@ -12,6 +12,8 @@ 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'
|
||||
@ -35,8 +37,7 @@ class Contract(ModelSQL, ModelView):
|
||||
party = fields.Many2One(
|
||||
'party.party', "Party", readonly=True, required=True,
|
||||
help="The party who subscribes.")
|
||||
contact = fields.Many2One(
|
||||
'party.contact_mechanism', "Contact", readonly=True)
|
||||
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'))])
|
||||
invoice_recurrence = fields.Many2One(
|
||||
@ -74,6 +75,8 @@ class Contract(ModelSQL, ModelView):
|
||||
('state', '=', 'uncontrated')]
|
||||
])
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
@ -82,21 +85,50 @@ class Contract(ModelSQL, ModelView):
|
||||
def default_state():
|
||||
return 'draft'
|
||||
|
||||
# @classmethod
|
||||
# @ModelView.button
|
||||
# def run(cls, subscription):
|
||||
# for equipment in cls.equipments:
|
||||
# if equipment.state == "contrated":
|
||||
# #aise UserError(str("El equipo"+str(equipment.number)
|
||||
# # +"No puede pertencer a este contrato porque
|
||||
# # ya se encuentra en un contrato"))
|
||||
# else:
|
||||
# continue
|
||||
|
||||
|
||||
|
||||
class CreateInitialContract(ModelView):
|
||||
'Create Initial Contract'
|
||||
__name__ = 'optical_equipment_contract.initial'
|
||||
|
||||
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.")
|
||||
party = fields.Many2One(
|
||||
'party.party', "Party", required=True,
|
||||
help="The party who subscribes.")
|
||||
invoice_address = fields.Many2One('party.address', 'Invoice Address',
|
||||
required=True, domain=[('party', '=', Eval('party'))])
|
||||
required=True, domain=[('party', '=', Eval('party'))])
|
||||
payment_term = fields.Many2One('account.invoice.payment_term',
|
||||
'Payment Term')
|
||||
contact = fields.Many2One(
|
||||
'party.contact_mechanism', "Contact", required=True)
|
||||
'party.contact_mechanism', "Contact", required=True,
|
||||
domain=[('party', '=', Eval('party'))],
|
||||
context={
|
||||
'company': Eval('company', -1),
|
||||
})
|
||||
start_date = fields.Date("Start Date", required=True)
|
||||
end_date = fields.Date("End Date", required=True)
|
||||
end_date = fields.Date("End Date",
|
||||
domain=['OR',
|
||||
('end_date', '>=', If(
|
||||
Bool(Eval('start_date')),
|
||||
Eval('start_date', datetime.date.min),
|
||||
datetime.date.min)),
|
||||
('end_date', '=', None),
|
||||
])
|
||||
invoice_recurrence = fields.Many2One('sale.subscription.recurrence.rule.set',
|
||||
"Invoice Recurrence",required=True)
|
||||
invoice_start_date = fields.Date("Invoice Start Date", required=True,
|
||||
@ -112,6 +144,10 @@ class CreateInitialContract(ModelView):
|
||||
('state', '=', 'registred'),
|
||||
('state', '=', 'uncontrated')]
|
||||
])
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@classmethod
|
||||
def default_start_date(cls):
|
||||
@ -119,12 +155,31 @@ class CreateInitialContract(ModelView):
|
||||
Date = pool.get('ir.date')
|
||||
return Date.today()
|
||||
|
||||
@classmethod
|
||||
def default_quantity(self):
|
||||
return 1
|
||||
|
||||
@fields.depends('invoice_recurrence')
|
||||
def on_change_invoice_recurrence(self):
|
||||
if self.invoice_recurrence.rules[0].freq == "yearly":
|
||||
pool = Pool()
|
||||
Date = pool.get('ir.date')
|
||||
self.end_date = Date.today() + timedelta(days=365)
|
||||
elif self.invoice_recurrence == None:
|
||||
self.end_date = None
|
||||
|
||||
|
||||
@classmethod
|
||||
@fields.depends(methods=['default_start_date'])
|
||||
def default_invoice_start_date(self):
|
||||
invoice_start_date = self.default_start_date()
|
||||
return invoice_start_date
|
||||
|
||||
@fields.depends('party')
|
||||
def on_change_party(self):
|
||||
if self.party:
|
||||
self.invoice_address = self.party.address_get(type='invoice')
|
||||
|
||||
class CreateContract(Wizard):
|
||||
'Create Contract'
|
||||
__name__ = 'sale.create.contract'
|
||||
@ -159,8 +214,6 @@ class CreateContract(Wizard):
|
||||
|
||||
def _create_contract_base(self,dates, subscription):
|
||||
pool = Pool()
|
||||
#Subscription = pool.get('sale.subscription')
|
||||
#subscription = Subscription.search(['id', '=', subscription.id])
|
||||
ContractBase = pool.get('optical_equipment.contract')
|
||||
|
||||
a = self._subscription_start
|
||||
@ -215,18 +268,17 @@ class CreateContract(Wizard):
|
||||
subscription.save()
|
||||
despues = subscription.id
|
||||
andes = str(antes) + str(despues)
|
||||
#raise UserError(str(andes))
|
||||
self._create_contract_base(a, subscription)
|
||||
|
||||
|
||||
|
||||
class CreateNextProrogue(ModelView):
|
||||
'Create Next Prorogue'
|
||||
__name__ = 'optical_equipment_prorogue.next'
|
||||
|
||||
initial_contract = fields.Many2One('optical_equipment.contract', "Initial Contract")
|
||||
party = fields.Many2One('party.party', "Party", required=True,
|
||||
domain=[('party', '=', Eval('party'))],
|
||||
help="The party who subscribes.")
|
||||
initial_contract = fields.Many2One('optical_equipment.contract', "Initial Contract")
|
||||
contact = fields.Many2One('party.contact_mechanism', "Contact")
|
||||
invoice_address = fields.Many2One('party.address', 'Invoice Address',
|
||||
required=True, domain=[('party', '=', Eval('party'))])
|
||||
@ -277,6 +329,7 @@ class CreateNextProrogue(ModelView):
|
||||
self.start_date = None
|
||||
self.equipments = []
|
||||
|
||||
|
||||
class CreateProrogue(Wizard):
|
||||
'Create Prorogue'
|
||||
__name__ = 'optical_equipment.prorogue'
|
||||
@ -356,11 +409,13 @@ class CreateProrogue(Wizard):
|
||||
contract.contact = a['contact']
|
||||
contract.invoice_recurrence = a['invoice_recurrence']
|
||||
contract.state = subscription.state
|
||||
|
||||
contract.prorogues += (contract.id,)
|
||||
#raise UserError(str(contract.id))
|
||||
|
||||
contract.prorogues += (subscription.id,)
|
||||
|
||||
contract.equipments = equipments_to_subscription
|
||||
contract.save()
|
||||
|
||||
|
||||
class Subscription(metaclass=PoolMeta):
|
||||
__name__ = 'sale.subscription'
|
||||
@ -412,6 +467,7 @@ class Subscription(metaclass=PoolMeta):
|
||||
Line.save(lines)
|
||||
cls.save(subscriptions)
|
||||
|
||||
|
||||
class CreateSubscriptionInvoice(Wizard):
|
||||
"Create Subscription Invoice"
|
||||
__name__ = 'sale.subscription.create_invoice'
|
||||
@ -477,6 +533,7 @@ class ContractEquipment(ModelSQL):
|
||||
equipment = fields.Many2One('optical_equipment.equipment', 'Equipment', select=True)
|
||||
contract = fields.Many2One('optical_equipment.contract', 'Contract', select=True)
|
||||
|
||||
|
||||
class SubscriptionEquipment(ModelSQL):
|
||||
'Optical Equipment - Subscription'
|
||||
__name__ = 'sale.subscription-optical_equipment.equipment'
|
||||
@ -484,6 +541,7 @@ class SubscriptionEquipment(ModelSQL):
|
||||
subscription = fields.Many2One('sale.subscription', 'Subscription', select=True)
|
||||
equipment = fields.Many2One('optical_equipment.equipment', 'Equipment', select=True)
|
||||
|
||||
|
||||
class ContractSupscription(ModelSQL):
|
||||
'Prorrogation to the Contract'
|
||||
__name__='sale.subscription-optical_equipment.contract'
|
||||
|
@ -109,6 +109,10 @@
|
||||
<field name="name">Prorogue to Contract</field>
|
||||
<field name="wiz_name">optical_equipment.prorogue</field>
|
||||
</record>
|
||||
<record model="ir.model.button" id="run_prorrogation_button">
|
||||
<field name="name">run</field>
|
||||
<field name="model" search="[('model', '=', 'optical_equipment.contract')]"/>
|
||||
</record>
|
||||
<menuitem
|
||||
name="Contracts Management"
|
||||
sequence="50"
|
||||
|
Loading…
Reference in New Issue
Block a user