Fix: Add field total_order
This commit is contained in:
parent
096386d8f7
commit
12e42a67d0
@ -13,6 +13,9 @@ class SaleOrder(ModelView, ModelSQL):
|
||||
"Sale Order"
|
||||
__name__ = 'sale.order'
|
||||
|
||||
company = fields.Many2One(
|
||||
'company.company', "Company", required=True
|
||||
)
|
||||
party = fields.Many2One(
|
||||
'party.party', "Party", required=True
|
||||
)
|
||||
@ -23,29 +26,63 @@ class SaleOrder(ModelView, ModelSQL):
|
||||
lines = fields.One2Many(
|
||||
'order.line', 'order', 'Lines'
|
||||
)
|
||||
date = fields.Date("Date", required=True)
|
||||
date = fields.Date("Date", required=True
|
||||
)
|
||||
currency = fields.Many2One(
|
||||
'currency.currency', 'Currency', required=True
|
||||
)
|
||||
total_order = fields.Function(
|
||||
Monetary("Total", currency='currency', digits='currency'),
|
||||
'on_change_with_total_order'
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@staticmethod
|
||||
def default_date():
|
||||
return date.today()
|
||||
|
||||
@fields.depends('lines')
|
||||
def on_change_with_total_order(self, name=None):
|
||||
total = Decimal('0.0')
|
||||
if self.lines:
|
||||
for line in self.lines:
|
||||
if line.total_amount:
|
||||
total += Decimal(line.total_amount)
|
||||
return total
|
||||
|
||||
@classmethod
|
||||
def default_currency(cls, **pattern):
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
company = pattern.get('company')
|
||||
if not company:
|
||||
company = cls.default_company()
|
||||
if company:
|
||||
return Company(company).currency.id
|
||||
|
||||
|
||||
class OrderLine(ModelView, ModelSQL):
|
||||
"Order Line"
|
||||
__name__ = 'order.line'
|
||||
|
||||
company = fields.Many2One(
|
||||
'company.company', "Company", required=True)
|
||||
'company.company', "Company", required=True
|
||||
)
|
||||
order = fields.Many2One(
|
||||
'sale.order', "Sale"
|
||||
)
|
||||
currency = fields.Many2One(
|
||||
'currency.currency', 'Currency', required=True)
|
||||
'currency.currency', 'Currency', required=True
|
||||
)
|
||||
product = fields.Many2One(
|
||||
'product.product', 'Product', required=True
|
||||
)
|
||||
unit = fields.Many2One(
|
||||
'product.uom', 'Unit')
|
||||
'product.uom', 'Unit'
|
||||
)
|
||||
product_uom_category = fields.Function(
|
||||
fields.Many2One('product.uom.category', 'Product UOM Category'),
|
||||
'on_change_with_product_uom_category'
|
||||
|
@ -41,5 +41,8 @@ Create order::
|
||||
>>> line1.quantity = 4.0
|
||||
>>> line1.unitprice = Decimal('8400')
|
||||
>>> line1.total_amount = Decimal('33600')
|
||||
>>> order.total_order = Decimal('33600')
|
||||
>>> order.save()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user