minor fix

This commit is contained in:
wilsongomez 2022-03-03 08:41:01 -05:00
parent 932a93ce4b
commit c9b8ba33c1
12 changed files with 219 additions and 0 deletions

View File

@ -3,6 +3,7 @@
from trytond.pool import Pool
from . import product
from . import position
from . import stock
from . import shipment
from . import inventory
@ -11,6 +12,9 @@ from . import inventory
def register():
Pool.register(
product.Product,
product.Template,
position.ProductPosition,
position.ProductTemplatePosition,
stock.Move,
stock.MoveByProductStart,
stock.Lot,

46
position.py Normal file
View File

@ -0,0 +1,46 @@
# 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
class ProductPosition(ModelSQL, ModelView):
"Product Position"
__name__ = "product.position"
name = fields.Char('Name', required=True)
parent = fields.Many2One('product.position', 'Parent')
warehouse = fields.Many2One('stock.location', 'Warehouse', states={
'required': True
}, domain=[('type', '=', 'warehouse')]
)
childs = fields.One2Many('product.position', 'parent', string='Children')
@classmethod
def __setup__(cls):
super(ProductPosition, cls).__setup__()
cls._order.insert(0, ('name', 'ASC'))
def get_rec_name(self, name):
if self.parent:
return self.parent.get_rec_name(name) + ' / ' + self.name
else:
return self.name
class ProductTemplatePosition(ModelSQL, ModelView):
"Product Template Position"
__name__ = 'product_template.position'
# _rec_name = 'position'
position = fields.Many2One('product.position', 'Position', required=True, ondelete='CASCADE')
template = fields.Many2One('product.template', 'Template', required=True, ondelete='RESTRICT')
warehouse =fields.Function(fields.Many2One('stock.location', 'Warehouse'), 'on_change_with_warehouse')
def get_rec_name(self, name):
return '[ ' + self.position.warehouse.name + ' ]' + self.position.rec_name
@fields.depends('position')
def on_change_with_warehouse(self):
warehouse = None
if self.position:
warehouse = self.position.warehouse.id
return warehouse

91
position.xml Normal file
View File

@ -0,0 +1,91 @@
<?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="position_view_tree">
<field name="model">product.position</field>
<field name="type">tree</field>
<field name="priority">10</field>
<field name="name">position_tree</field>
</record>
<record model="ir.ui.view" id="position_view_tree2">
<field name="model">product.position</field>
<field name="type">tree</field>
<field name="priority">20</field>
<field name="field_childs">childs</field>
<field name="name">position_tree2</field>
</record>
<record model="ir.ui.view" id="position_view_form">
<field name="model">product.position</field>
<field name="type">form</field>
<field name="name">position_form</field>
</record>
<record model="ir.action.act_window" id="act_position_tree">
<field name="name">Positions</field>
<field name="res_model">product.position</field>
<field name="domain" eval="[('parent', '=', None)]" pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_position_tree_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="position_view_tree2"/>
<field name="act_window" ref="act_position_tree"/>
</record>
<record model="ir.action.act_window.view" id="act_position_tree_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="position_view_form"/>
<field name="act_window" ref="act_position_tree"/>
</record>
<menuitem parent="product.menu_main_product" sequence="1"
action="act_position_tree" id="menu_position_tree"/>
<record model="ir.model.access" id="access_product_position">
<field name="model" search="[('model', '=', 'product.position')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
<field name="perm_delete" eval="False"/>
</record>
<record model="ir.model.access" id="access_product_position_admin">
<field name="model" search="[('model', '=', 'product.position')]"/>
<field name="group" ref="product.group_product_admin"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
<field name="perm_create" eval="True"/>
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.ui.view" id="position_template_view_tree">
<field name="model">product_template.position</field>
<field name="type">tree</field>
<field name="priority">10</field>
<field name="name">position_template_tree</field>
</record>
<record model="ir.ui.view" id="position_template_view_form">
<field name="model">product_template.position</field>
<field name="type">form</field>
<field name="priority">20</field>
<field name="name">position_template_form</field>
</record>
<record model="ir.action.act_window" id="act_position_template">
<field name="name">Positions Template</field>
<field name="res_model">product_template.position</field>
<!-- <field name="domain" eval="[('parent', '=', None)]" pyson="1"/> -->
</record>
<record model="ir.action.act_window.view" id="act_position_template_tree_view1">
<field name="sequence" eval="1"/>
<field name="view" ref="position_template_view_tree"/>
<field name="act_window" ref="act_position_template"/>
</record>
<record model="ir.action.act_window.view" id="act_position_template_tree_view2">
<field name="sequence" eval="2"/>
<field name="view" ref="position_template_view_form"/>
<field name="act_window" ref="act_position_template"/>
</record>
</data>
</tryton>

View File

@ -13,6 +13,7 @@ TIME_HISTORY = 90 # Days
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
stock_duration = fields.Function(fields.Integer('Stock Duration',
states=STATES), 'get_stock_duration')
stock_level = fields.Function(fields.Selection([
@ -67,3 +68,9 @@ class Product(metaclass=PoolMeta):
res = 'exhausted'
"""
return res
class Template(metaclass=PoolMeta):
__name__ = 'product.template'
positions = fields.One2Many('product_template.position','template', 'Positions')

View File

@ -16,5 +16,11 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">product_form</field>
</record>
<record model="ir.ui.view" id="template_view_form">
<field name="model">product.template</field>
<field name="inherit" ref="product.template_view_form"/>
<field name="name">template_form</field>
</record>
</data>
</tryton>

View File

@ -11,3 +11,4 @@ xml:
stock.xml
shipment.xml
inventory.xml
position.xml

18
view/position_form.xml Normal file
View File

@ -0,0 +1,18 @@
<?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="name"/>
<field name="name"/>
<label name="parent"/>
<field name="parent" widget="selection"/>
<label name="warehouse"/>
<field name="warehouse"/>
<label name="rec_name"/>
<field name="rec_name" colspan="3"/>
<notebook colspan="4">
<page string="Children" col="1" id="childs">
<field name="childs"/>
</page>
</notebook>
</form>

View File

@ -0,0 +1,9 @@
<?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="warehouse"/>
<field name="warehouse"/>
<label name="position"/>
<field name="position"/>
</form>

View 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>
<field name="warehouse" expand="1"/>
<field name="position" expand="1"/>
</tree>

7
view/position_tree.xml Normal file
View 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>
<field name="name"/>
<field name="rec_name"/>
</tree>

6
view/position_tree2.xml Normal file
View File

@ -0,0 +1,6 @@
<?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>
<field name="name"/>
</tree>

17
view/template_form.xml Normal file
View File

@ -0,0 +1,17 @@
<?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. -->
<data>
<xpath expr="/form/notebook/page[@id='general']/field[@name='list_price']"
position="after">
<label name="sale_price_w_tax"/>
<field name="sale_price_w_tax"/>
</xpath>
<xpath
expr="/form/notebook/page[@id='accounting']"
position="after">
<page string="Positions" id="positions">
<field name="positions" colspan="4"/>
</page>
</xpath>
</data>