add field 'equipment' which contains the relation with 'optical_equipment.equipment'
This commit is contained in:
parent
425c7e225a
commit
9bb6f4066c
70
sale.py
70
sale.py
@ -1,6 +1,8 @@
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import Eval, Bool, If
|
||||
from decimal import Decimal
|
||||
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
@ -47,27 +49,51 @@ class CreateSubscription(Wizard):
|
||||
|
||||
@property
|
||||
def _subscription_start(self):
|
||||
return dict(
|
||||
start_date = self.start.start_date,
|
||||
end_date = self.start.end_date,
|
||||
invoice_recurrence = self.start.invoice_recurrence,
|
||||
invoice_start_date = self.start.invoice_start_date,
|
||||
service = self.start.service,
|
||||
quantity = self.start.quantity)
|
||||
#raise UserError(str(dir(self)))
|
||||
sale = self.records[0]
|
||||
#raise UserError(str(dir(self.records[0])))
|
||||
return dict(start_date = self.start.start_date,
|
||||
end_date = self.start.end_date,
|
||||
invoice_recurrence = self.start.invoice_recurrence,
|
||||
invoice_start_date = self.start.invoice_start_date,service = self.start.service,
|
||||
quantity = self.start.quantity,
|
||||
party=sale.party.id,
|
||||
contact=sale.contact.id if sale.contact else None,
|
||||
invoice_party=sale.invoice_party.id if sale.invoice_party else None,
|
||||
invoice_address=sale.invoice_address.id,
|
||||
payment_term=sale.payment_term.id if sale.payment_term else None)
|
||||
|
||||
def do_create_subscription(self, action):
|
||||
pool = Pool()
|
||||
Subscription = pool.get('sale.subscription')
|
||||
#SubscriptionLine = pool.get('sale.subscription.line')
|
||||
raise UserError(str(dir(Subscription.lines)))
|
||||
a = self._subscription_start
|
||||
subscription = Subscription(
|
||||
start_date=a['start_date'],
|
||||
end_date=a['end_date'],
|
||||
invoice_recurrence=a['invoice_recurrence'],
|
||||
invoice_start_date=a['invoice_start_date'],
|
||||
party=a['party'],
|
||||
contact=a['contact'],
|
||||
invoice_party=a['contact'],
|
||||
invoice_address=a['invoice_address'],
|
||||
payment_term=a['payment_term'],
|
||||
)
|
||||
subscription.save()
|
||||
|
||||
#raise UserError(str(dir(subscription)))
|
||||
|
||||
#subscription = subscription()
|
||||
self._subscription_start
|
||||
|
||||
class SaleLine(metaclass=PoolMeta):
|
||||
'SaleLine'
|
||||
__name__ = 'sale.line'
|
||||
|
||||
address_equipment = fields.Many2One('party.address', "Direccion")
|
||||
product_equipment = fields.Boolean("Product Equipment")
|
||||
equipment = fields.Many2One('optical_equipment.equipment', "Equipment",
|
||||
domain=[('state', '=', 'registred')],
|
||||
states={'invisible': If(~Eval('product_equipment'), True)})
|
||||
address_equipment = fields.Many2One('party.address', "Direccion")
|
||||
unit_digits = fields.Function(fields.Integer('Unit Digits'),
|
||||
'on_change_with_unit_digits')
|
||||
|
||||
@ -77,13 +103,35 @@ class SaleLine(metaclass=PoolMeta):
|
||||
return self.unit.digits
|
||||
return 2
|
||||
|
||||
@fields.depends('equipment', methods=['on_change_product'])
|
||||
def on_change_equipment(self):
|
||||
if self.equipment:
|
||||
self.product = self.equipment.product.id
|
||||
self.on_change_product()
|
||||
else:
|
||||
self.product = None
|
||||
self.unit= None
|
||||
self.quantity = None
|
||||
self.unit_price = None
|
||||
self.amount = None
|
||||
self.on_change_product()
|
||||
|
||||
@fields.depends('product_equipment', methods=['on_change_equipment'])
|
||||
def on_change_product_equipment(self):
|
||||
if self.product_equipment == False:
|
||||
self.equipment = None
|
||||
#self.on_change_equipment()
|
||||
|
||||
|
||||
|
||||
@fields.depends('product', 'unit', 'quantity', 'sale',
|
||||
'_parent_sale.party',methods=['_get_tax_rule_pattern',
|
||||
'_parent_sale.party',methods=['_get_tax_rule_pattern',
|
||||
'_get_context_sale_price','on_change_with_amount'])
|
||||
def on_change_product(self):
|
||||
Product = Pool().get('product.product')
|
||||
if not self.product:
|
||||
self.product_equipment = False
|
||||
self.unit = None
|
||||
return
|
||||
|
||||
party = None
|
||||
|
@ -9,8 +9,10 @@
|
||||
</page>
|
||||
</xpath>
|
||||
<xpath
|
||||
expr="/form/notebook/page[@id='general']/field[@name='product']" position="after">
|
||||
expr="/form/notebook/page[@id='general']/label[@name='product']" position="before">
|
||||
<label name="product_equipment"/>
|
||||
<field name="product_equipment"/>
|
||||
<label name="equipment"/>
|
||||
<field name="equipment"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
Loading…
Reference in New Issue
Block a user