Add brach 7.4, fields orde.line and xmls
This commit is contained in:
parent
de6b2e3c14
commit
b3b74c1f69
@ -7,6 +7,7 @@ __all__ = ['register']
|
||||
def register():
|
||||
Pool.register(
|
||||
sale_order.SaleOrder,
|
||||
sale_order.OrderLine,
|
||||
module='sale_order', type_='model')
|
||||
Pool.register(
|
||||
module='sale_order', type_='wizard')
|
||||
|
@ -1,4 +1,10 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.modules.currency.fields import Monetary
|
||||
from trytond.modules.product import price_digits
|
||||
from trytond.pyson import Eval
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class SaleOrder(ModelView, ModelSQL):
|
||||
@ -12,3 +18,53 @@ class SaleOrder(ModelView, ModelSQL):
|
||||
[("on_site", "On Site"),
|
||||
("at_home", "At Home")], 'Pickup Location'
|
||||
)
|
||||
lines = fields.One2Many(
|
||||
'order.line', 'order', 'Lines'
|
||||
)
|
||||
|
||||
|
||||
class OrderLine(ModelView, ModelSQL):
|
||||
"Order Line"
|
||||
__name__ = 'order.line'
|
||||
|
||||
order = fields.Many2One(
|
||||
'sale.order', "Sale"
|
||||
)
|
||||
product = fields.Many2One(
|
||||
'product.product', 'Product', required=True
|
||||
)
|
||||
unit = fields.Many2One(
|
||||
'product.uom', 'Unit',
|
||||
domain=[
|
||||
('category', '=', Eval('product_uom_category')),
|
||||
],
|
||||
depends=['product_uom_category']
|
||||
)
|
||||
product_uom_category = fields.Function(
|
||||
fields.Many2One('product.uom.category', 'Product UOM Category'),
|
||||
'on_change_with_product_uom_category'
|
||||
)
|
||||
quantity = fields.Float(
|
||||
"Quantity", digits=('unit')
|
||||
)
|
||||
unitprice = Monetary(
|
||||
"Unit Price", digits=price_digits, currency='currency'
|
||||
)
|
||||
total_amount = fields.Function(
|
||||
Monetary("Total Amount", currency='currency', digits='currency'),
|
||||
'get_total_amount'
|
||||
)
|
||||
|
||||
@fields.depends('product')
|
||||
def on_change_with_product_uom_category(self, name=None):
|
||||
if self.product:
|
||||
return self.product.default_uom.category.id
|
||||
return None
|
||||
|
||||
@fields.depends('quantity', 'unitprice')
|
||||
def on_change_with_total_amount(self):
|
||||
total_amount = self.unitprice * Decimal(self.quantity)
|
||||
return total_amount
|
||||
|
||||
def get_total_amount(self):
|
||||
return self.on_change_with_total_amount()
|
||||
|
27
sale_order.xml
Normal file
27
sale_order.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="sale_order_view_tree">
|
||||
<field name="model">sale.order</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">order_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="sale_order_view_form">
|
||||
<field name="model">sale.order</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">order_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="order_line_view_tree">
|
||||
<field name="model">order.line</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="name">line_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="order_line_view_form">
|
||||
<field name="model">order.line</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">line_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
@ -37,8 +37,9 @@ Create order::
|
||||
>>> order.save()
|
||||
>>> line1 = order.lines.new()
|
||||
>>> line1.product = product
|
||||
>>> line1.quantity = 4
|
||||
>>> line1.unitprice = 8400
|
||||
>>> line1.total_amount = 33600
|
||||
>>> line1.unit = unit
|
||||
>>> line1.quantity = 4.0
|
||||
>>> line1.unitprice = Decimal('8400')
|
||||
>>> line1.total_amount = Decimal('33600')
|
||||
>>> order.save()
|
||||
|
14
view/order_form.xml
Normal file
14
view/order_form.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="party"/>
|
||||
<field name="party"/>
|
||||
<label name="pickup_location"/>
|
||||
<field name="pickup_location"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Order Lines" col="1" id="line">
|
||||
<field name=""/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
7
view/order_tree.xml
Normal file
7
view/order_tree.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree keyword_open="1">
|
||||
<field name="party" expand="1"/>
|
||||
<field name="pickup_location" expand="1"/>
|
||||
</tree>
|
Loading…
Reference in New Issue
Block a user