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
|
from trytond.modules.product import price_digits
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
||||||
class Contract(ModelSQL, ModelView):
|
class Contract(ModelSQL, ModelView):
|
||||||
'Contracts'
|
'Contracts'
|
||||||
@ -35,8 +37,7 @@ class Contract(ModelSQL, ModelView):
|
|||||||
party = fields.Many2One(
|
party = fields.Many2One(
|
||||||
'party.party', "Party", readonly=True, required=True,
|
'party.party', "Party", readonly=True, required=True,
|
||||||
help="The party who subscribes.")
|
help="The party who subscribes.")
|
||||||
contact = fields.Many2One(
|
contact = fields.Many2One('party.contact_mechanism', "Contact", readonly=True)
|
||||||
'party.contact_mechanism', "Contact", readonly=True)
|
|
||||||
invoice_address = fields.Many2One('party.address', 'Invoice Address', readonly=True,
|
invoice_address = fields.Many2One('party.address', 'Invoice Address', readonly=True,
|
||||||
required=True, domain=[('party', '=', Eval('party'))])
|
required=True, domain=[('party', '=', Eval('party'))])
|
||||||
invoice_recurrence = fields.Many2One(
|
invoice_recurrence = fields.Many2One(
|
||||||
@ -74,6 +75,8 @@ class Contract(ModelSQL, ModelView):
|
|||||||
('state', '=', 'uncontrated')]
|
('state', '=', 'uncontrated')]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def default_company():
|
def default_company():
|
||||||
return Transaction().context.get('company')
|
return Transaction().context.get('company')
|
||||||
@ -82,10 +85,28 @@ class Contract(ModelSQL, ModelView):
|
|||||||
def default_state():
|
def default_state():
|
||||||
return 'draft'
|
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):
|
class CreateInitialContract(ModelView):
|
||||||
'Create Initial Contract'
|
'Create Initial Contract'
|
||||||
__name__ = 'optical_equipment_contract.initial'
|
__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 = fields.Many2One(
|
||||||
'party.party', "Party", required=True,
|
'party.party', "Party", required=True,
|
||||||
help="The party who subscribes.")
|
help="The party who subscribes.")
|
||||||
@ -94,9 +115,20 @@ class CreateInitialContract(ModelView):
|
|||||||
payment_term = fields.Many2One('account.invoice.payment_term',
|
payment_term = fields.Many2One('account.invoice.payment_term',
|
||||||
'Payment Term')
|
'Payment Term')
|
||||||
contact = fields.Many2One(
|
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)
|
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 = fields.Many2One('sale.subscription.recurrence.rule.set',
|
||||||
"Invoice Recurrence",required=True)
|
"Invoice Recurrence",required=True)
|
||||||
invoice_start_date = fields.Date("Invoice Start Date", required=True,
|
invoice_start_date = fields.Date("Invoice Start Date", required=True,
|
||||||
@ -113,18 +145,41 @@ class CreateInitialContract(ModelView):
|
|||||||
('state', '=', 'uncontrated')]
|
('state', '=', 'uncontrated')]
|
||||||
])
|
])
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def default_company():
|
||||||
|
return Transaction().context.get('company')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def default_start_date(cls):
|
def default_start_date(cls):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Date = pool.get('ir.date')
|
Date = pool.get('ir.date')
|
||||||
return Date.today()
|
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
|
@classmethod
|
||||||
@fields.depends(methods=['default_start_date'])
|
@fields.depends(methods=['default_start_date'])
|
||||||
def default_invoice_start_date(self):
|
def default_invoice_start_date(self):
|
||||||
invoice_start_date = self.default_start_date()
|
invoice_start_date = self.default_start_date()
|
||||||
return invoice_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):
|
class CreateContract(Wizard):
|
||||||
'Create Contract'
|
'Create Contract'
|
||||||
__name__ = 'sale.create.contract'
|
__name__ = 'sale.create.contract'
|
||||||
@ -159,8 +214,6 @@ class CreateContract(Wizard):
|
|||||||
|
|
||||||
def _create_contract_base(self,dates, subscription):
|
def _create_contract_base(self,dates, subscription):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
#Subscription = pool.get('sale.subscription')
|
|
||||||
#subscription = Subscription.search(['id', '=', subscription.id])
|
|
||||||
ContractBase = pool.get('optical_equipment.contract')
|
ContractBase = pool.get('optical_equipment.contract')
|
||||||
|
|
||||||
a = self._subscription_start
|
a = self._subscription_start
|
||||||
@ -215,18 +268,17 @@ class CreateContract(Wizard):
|
|||||||
subscription.save()
|
subscription.save()
|
||||||
despues = subscription.id
|
despues = subscription.id
|
||||||
andes = str(antes) + str(despues)
|
andes = str(antes) + str(despues)
|
||||||
#raise UserError(str(andes))
|
|
||||||
self._create_contract_base(a, subscription)
|
self._create_contract_base(a, subscription)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CreateNextProrogue(ModelView):
|
class CreateNextProrogue(ModelView):
|
||||||
'Create Next Prorogue'
|
'Create Next Prorogue'
|
||||||
__name__ = 'optical_equipment_prorogue.next'
|
__name__ = 'optical_equipment_prorogue.next'
|
||||||
|
|
||||||
initial_contract = fields.Many2One('optical_equipment.contract', "Initial Contract")
|
|
||||||
party = fields.Many2One('party.party', "Party", required=True,
|
party = fields.Many2One('party.party', "Party", required=True,
|
||||||
|
domain=[('party', '=', Eval('party'))],
|
||||||
help="The party who subscribes.")
|
help="The party who subscribes.")
|
||||||
|
initial_contract = fields.Many2One('optical_equipment.contract', "Initial Contract")
|
||||||
contact = fields.Many2One('party.contact_mechanism', "Contact")
|
contact = fields.Many2One('party.contact_mechanism', "Contact")
|
||||||
invoice_address = fields.Many2One('party.address', 'Invoice Address',
|
invoice_address = fields.Many2One('party.address', 'Invoice Address',
|
||||||
required=True, domain=[('party', '=', Eval('party'))])
|
required=True, domain=[('party', '=', Eval('party'))])
|
||||||
@ -277,6 +329,7 @@ class CreateNextProrogue(ModelView):
|
|||||||
self.start_date = None
|
self.start_date = None
|
||||||
self.equipments = []
|
self.equipments = []
|
||||||
|
|
||||||
|
|
||||||
class CreateProrogue(Wizard):
|
class CreateProrogue(Wizard):
|
||||||
'Create Prorogue'
|
'Create Prorogue'
|
||||||
__name__ = 'optical_equipment.prorogue'
|
__name__ = 'optical_equipment.prorogue'
|
||||||
@ -356,12 +409,14 @@ class CreateProrogue(Wizard):
|
|||||||
contract.contact = a['contact']
|
contract.contact = a['contact']
|
||||||
contract.invoice_recurrence = a['invoice_recurrence']
|
contract.invoice_recurrence = a['invoice_recurrence']
|
||||||
contract.state = subscription.state
|
contract.state = subscription.state
|
||||||
|
#raise UserError(str(contract.id))
|
||||||
|
|
||||||
contract.prorogues += (contract.id,)
|
contract.prorogues += (subscription.id,)
|
||||||
|
|
||||||
contract.equipments = equipments_to_subscription
|
contract.equipments = equipments_to_subscription
|
||||||
contract.save()
|
contract.save()
|
||||||
|
|
||||||
|
|
||||||
class Subscription(metaclass=PoolMeta):
|
class Subscription(metaclass=PoolMeta):
|
||||||
__name__ = 'sale.subscription'
|
__name__ = 'sale.subscription'
|
||||||
|
|
||||||
@ -412,6 +467,7 @@ class Subscription(metaclass=PoolMeta):
|
|||||||
Line.save(lines)
|
Line.save(lines)
|
||||||
cls.save(subscriptions)
|
cls.save(subscriptions)
|
||||||
|
|
||||||
|
|
||||||
class CreateSubscriptionInvoice(Wizard):
|
class CreateSubscriptionInvoice(Wizard):
|
||||||
"Create Subscription Invoice"
|
"Create Subscription Invoice"
|
||||||
__name__ = 'sale.subscription.create_invoice'
|
__name__ = 'sale.subscription.create_invoice'
|
||||||
@ -477,6 +533,7 @@ class ContractEquipment(ModelSQL):
|
|||||||
equipment = fields.Many2One('optical_equipment.equipment', 'Equipment', select=True)
|
equipment = fields.Many2One('optical_equipment.equipment', 'Equipment', select=True)
|
||||||
contract = fields.Many2One('optical_equipment.contract', 'Contract', select=True)
|
contract = fields.Many2One('optical_equipment.contract', 'Contract', select=True)
|
||||||
|
|
||||||
|
|
||||||
class SubscriptionEquipment(ModelSQL):
|
class SubscriptionEquipment(ModelSQL):
|
||||||
'Optical Equipment - Subscription'
|
'Optical Equipment - Subscription'
|
||||||
__name__ = 'sale.subscription-optical_equipment.equipment'
|
__name__ = 'sale.subscription-optical_equipment.equipment'
|
||||||
@ -484,6 +541,7 @@ class SubscriptionEquipment(ModelSQL):
|
|||||||
subscription = fields.Many2One('sale.subscription', 'Subscription', select=True)
|
subscription = fields.Many2One('sale.subscription', 'Subscription', select=True)
|
||||||
equipment = fields.Many2One('optical_equipment.equipment', 'Equipment', select=True)
|
equipment = fields.Many2One('optical_equipment.equipment', 'Equipment', select=True)
|
||||||
|
|
||||||
|
|
||||||
class ContractSupscription(ModelSQL):
|
class ContractSupscription(ModelSQL):
|
||||||
'Prorrogation to the Contract'
|
'Prorrogation to the Contract'
|
||||||
__name__='sale.subscription-optical_equipment.contract'
|
__name__='sale.subscription-optical_equipment.contract'
|
||||||
|
@ -109,6 +109,10 @@
|
|||||||
<field name="name">Prorogue to Contract</field>
|
<field name="name">Prorogue to Contract</field>
|
||||||
<field name="wiz_name">optical_equipment.prorogue</field>
|
<field name="wiz_name">optical_equipment.prorogue</field>
|
||||||
</record>
|
</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
|
<menuitem
|
||||||
name="Contracts Management"
|
name="Contracts Management"
|
||||||
sequence="50"
|
sequence="50"
|
||||||
|
Loading…
Reference in New Issue
Block a user