add field 'equipment' which contains the relation with 'optical_equipment.equipment'
This commit is contained in:
parent
425c7e225a
commit
9bb6f4066c
64
sale.py
64
sale.py
@ -1,6 +1,8 @@
|
|||||||
from trytond.pool import Pool, PoolMeta
|
from trytond.pool import Pool, PoolMeta
|
||||||
from trytond.model import ModelView, ModelSQL, fields
|
from trytond.model import ModelView, ModelSQL, fields
|
||||||
from trytond.pyson import Eval, Bool, If
|
from trytond.pyson import Eval, Bool, If
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
from trytond.transaction import Transaction
|
from trytond.transaction import Transaction
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
|
|
||||||
@ -47,27 +49,51 @@ class CreateSubscription(Wizard):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def _subscription_start(self):
|
def _subscription_start(self):
|
||||||
return dict(
|
#raise UserError(str(dir(self)))
|
||||||
start_date = self.start.start_date,
|
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,
|
end_date = self.start.end_date,
|
||||||
invoice_recurrence = self.start.invoice_recurrence,
|
invoice_recurrence = self.start.invoice_recurrence,
|
||||||
invoice_start_date = self.start.invoice_start_date,
|
invoice_start_date = self.start.invoice_start_date,service = self.start.service,
|
||||||
service = self.start.service,
|
quantity = self.start.quantity,
|
||||||
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):
|
def do_create_subscription(self, action):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Subscription = pool.get('sale.subscription')
|
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):
|
class SaleLine(metaclass=PoolMeta):
|
||||||
'SaleLine'
|
'SaleLine'
|
||||||
__name__ = 'sale.line'
|
__name__ = 'sale.line'
|
||||||
|
|
||||||
address_equipment = fields.Many2One('party.address', "Direccion")
|
|
||||||
product_equipment = fields.Boolean("Product Equipment")
|
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'),
|
unit_digits = fields.Function(fields.Integer('Unit Digits'),
|
||||||
'on_change_with_unit_digits')
|
'on_change_with_unit_digits')
|
||||||
|
|
||||||
@ -77,6 +103,27 @@ class SaleLine(metaclass=PoolMeta):
|
|||||||
return self.unit.digits
|
return self.unit.digits
|
||||||
return 2
|
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',
|
@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'])
|
'_get_context_sale_price','on_change_with_amount'])
|
||||||
@ -84,6 +131,7 @@ class SaleLine(metaclass=PoolMeta):
|
|||||||
Product = Pool().get('product.product')
|
Product = Pool().get('product.product')
|
||||||
if not self.product:
|
if not self.product:
|
||||||
self.product_equipment = False
|
self.product_equipment = False
|
||||||
|
self.unit = None
|
||||||
return
|
return
|
||||||
|
|
||||||
party = None
|
party = None
|
||||||
|
@ -9,8 +9,10 @@
|
|||||||
</page>
|
</page>
|
||||||
</xpath>
|
</xpath>
|
||||||
<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"/>
|
<label name="product_equipment"/>
|
||||||
<field name="product_equipment"/>
|
<field name="product_equipment"/>
|
||||||
|
<label name="equipment"/>
|
||||||
|
<field name="equipment"/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</data>
|
</data>
|
||||||
|
Loading…
Reference in New Issue
Block a user