Skip to content

Commit

Permalink
Add relates to sale and purchase lines from party and product
Browse files Browse the repository at this point in the history
  • Loading branch information
cedk committed Jan 26, 2023
1 parent 0b159be commit 84514c4
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 8 deletions.
1 change: 1 addition & 0 deletions modules/purchase/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Add relate to purchase lines from party and product
* Simplify relate to purchases
* Prevent creation of lines for non draft purchases
* Allow searching reporting records by name
Expand Down
43 changes: 41 additions & 2 deletions modules/purchase/purchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
actual_quantity = fields.Float(
"Actual Quantity", digits='unit', readonly=True,
states={
'invisible': Eval('type') != 'line',
'invisible': ((Eval('type') != 'line') | ~Eval('actual_quantity')),
})
unit = fields.Many2One('product.uom', 'Unit',
ondelete='RESTRICT',
Expand Down Expand Up @@ -1205,10 +1205,20 @@ class Line(sequence_ordered(), ModelSQL, ModelView):
})
purchase_state = fields.Function(
fields.Selection('get_purchase_states', 'Purchase State'),
'on_change_with_purchase_state')
'on_change_with_purchase_state', searcher='search_purchase_state')
company = fields.Function(
fields.Many2One('company.company', "Company"),
'on_change_with_company')
supplier = fields.Function(
fields.Many2One(
'party.party', "Supplier",
context={
'company': Eval('company', -1),
}),
'on_change_with_supplier', searcher='search_supplier')
purchase_date = fields.Function(
fields.Date("Purchase Date"),
'on_change_with_purchase_date', searcher='search_purchase_date')
currency = fields.Function(
fields.Many2One('currency.currency', 'Currency'),
'on_change_with_currency')
Expand All @@ -1223,6 +1233,8 @@ def get_move_product_types(cls):
def __setup__(cls):
super().__setup__()
cls.__access__.add('purchase')
cls._order.insert(0, ('purchase.purchase_date', 'DESC NULLS FIRST'))
cls._order.insert(1, ('purchase.id', 'DESC'))

@classmethod
def __register__(cls, module_name):
Expand Down Expand Up @@ -1517,11 +1529,38 @@ def on_change_with_purchase_state(self, name=None):
if self.purchase:
return self.purchase.state

@classmethod
def search_purchase_state(cls, name, clause):
return [('purchase.state', *clause[1:])]

@fields.depends('purchase', '_parent_purchase.company')
def on_change_with_company(self, name=None):
if self.purchase and self.purchase.company:
return self.purchase.company.id

@fields.depends('purchase', '_parent_purchase.party')
def on_change_with_supplier(self, name=None):
if self.purchase and self.purchase.party:
return self.purchase.party.id

@classmethod
def search_supplier(cls, name, clause):
return [('purchase.party' + clause[0][len(name):], *clause[1:])]

@fields.depends('purchase', '_parent_purchase.purchase_date')
def on_change_with_purchase_date(self, name=None):
if self.purchase:
return self.purchase.purchase_date

@classmethod
def search_purchase_date(cls, name, clause):
return [('purchase.purchase_date', *clause[1:])]

@classmethod
def order_purchase_date(cls, tables):
return cls.purchase.convert_order(
'purchase.purchase_date', tables, cls)

@fields.depends('purchase', '_parent_purchase.currency')
def on_change_with_currency(self, name=None):
if self.purchase and self.purchase.currency:
Expand Down
68 changes: 68 additions & 0 deletions modules/purchase/purchase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,74 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">purchase_line_tree_sequence</field>
</record>

<record model="ir.action.act_window" id="act_purchase_line_relate">
<field name="name">Purchase Lines</field>
<field name="res_model">purchase.line</field>
<field
name="domain"
eval="[('type', '=', 'line'),
If(Eval('active_model') == 'purchase.purchase',
('purchase', 'in', Eval('active_ids', [])), ()),
If(Eval('active_model') == 'product.product',
('product', 'in', Eval('active_ids', [])), ()),
If(Eval('active_model') == 'product.template',
('product.template.id', 'in', Eval('active_ids', [])), ()),
If(Eval('active_model') == 'party.party',
('supplier', 'in', Eval('active_ids', [])), ()),
]"
pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_purchase_line_relate_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="purchase_line_view_tree"/>
<field name="act_window" ref="act_purchase_line_relate"/>
</record>
<record model="ir.action.act_window.view" id="act_purchase_line_relate_view2">
<field name="sequence" eval="20"/>
<field name="view" ref="purchase_line_view_form"/>
<field name="act_window" ref="act_purchase_line_relate"/>
</record>
<record model="ir.action.act_window.domain" id="act_purchase_line_relate_pending">
<field name="name">Pending</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('purchase_state', 'not in', ['done', 'cancelled'])]" pyson="1"/>
<field name="count" eval="True"/>
<field name="act_window" ref="act_purchase_line_relate"/>
</record>
<record model="ir.action.act_window.domain" id="act_purchase_line_relate_done">
<field name="name">Done</field>
<field name="sequence" eval="20"/>
<field name="domain" eval="[('purchase_state', '=', 'done')]" pyson="1"/>
<field name="count" eval="True"/>
<field name="act_window" ref="act_purchase_line_relate"/>
</record>
<record model="ir.action.act_window.domain" id="act_purchase_line_relate_all">
<field name="name">All</field>
<field name="sequence" eval="9999"/>
<field name="domain"></field>
<field name="act_window" ref="act_purchase_line_relate"/>
</record>
<record model="ir.action.keyword" id="act_purchase_line_relate_keyword_purchase">
<field name="keyword">form_relate</field>
<field name="model">purchase.purchase,-1</field>
<field name="action" ref="act_purchase_line_relate"/>
</record>
<record model="ir.action.keyword" id="act_purchase_line_relate_keyword_product">
<field name="keyword">form_relate</field>
<field name="model">product.product,-1</field>
<field name="action" ref="act_purchase_line_relate"/>
</record>
<record model="ir.action.keyword" id="act_purchase_line_relate_keyword_product_template">
<field name="keyword">form_relate</field>
<field name="model">product.template,-1</field>
<field name="action" ref="act_purchase_line_relate"/>
</record>
<record model="ir.action.keyword" id="act_purchase_line_relate_keyword_party">
<field name="keyword">form_relate</field>
<field name="model">party.party,-1</field>
<field name="action" ref="act_purchase_line_relate"/>
</record>

<record model="ir.model.access" id="access_purchase_line_group_stock">
<field name="model" search="[('model', '=', 'purchase.line')]"/>
<field name="group" ref="stock.group_stock"/>
Expand Down
1 change: 1 addition & 0 deletions modules/purchase/view/party_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//group[@id='links']" position="inside">
<link icon="tryton-purchase" name="purchase.act_purchase_relate" empty="hide"/>
<link icon="tryton-purchase" name="purchase.act_purchase_line_relate" empty="hide"/>
</xpath>
<xpath expr="/form/notebook/page[@id='general']" position="after">
<page string="Supplier" id="supplier">
Expand Down
7 changes: 5 additions & 2 deletions modules/purchase/view/purchase_line_tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="purchase" expand="1"/>
<field name="supplier" expand="1" optional="0"/>
<field name="purchase_date" optional="1"/>
<field name="type" optional="1"/>
<field name="product" expand="1" optional="0"/>
<field name="product_supplier" expand="1" optional="1"/>
<field name="summary" expand="1" optional="1"/>
<field name="quantity" symbol="unit"/>
<field name="actual_quantity" symbol="unit" optional="0"/>
<field name="quantity" symbol="unit" optional="0"/>
<field name="unit_price"/>
<field name="taxes" optional="0"/>
<field name="amount"/>
<field name="purchase_state"/>
</tree>
4 changes: 4 additions & 0 deletions modules/purchase/view/template_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="purchase_uom"/>
<field name="product_suppliers" colspan="4"
view_ids="purchase.product_supplier_view_tree_sequence"/>

<group id="suppliers_links" col="-1" colspan="4">
<link icon="tryton-purchase" name="purchase.act_purchase_line_relate" empty="hide"/>
</group>
</page>
</xpath>
</data>
1 change: 1 addition & 0 deletions modules/sale/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Add relate to sale lines from party and product
* Simplify relate to sales
* Prevent creation of lines for non draft sales
* Allow searching reporting records by name
Expand Down
42 changes: 40 additions & 2 deletions modules/sale/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
actual_quantity = fields.Float(
"Actual Quantity", digits='unit', readonly=True,
states={
'invisible': Eval('type') != 'line',
'invisible': ((Eval('type') != 'line') | ~Eval('actual_quantity')),
})
unit = fields.Many2One('product.uom', 'Unit', ondelete='RESTRICT',
states={
Expand Down Expand Up @@ -1255,10 +1255,20 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
'on_change_with_shipping_date')
sale_state = fields.Function(
fields.Selection('get_sale_states', "Sale State"),
'on_change_with_sale_state')
'on_change_with_sale_state', searcher='search_sale_state')
company = fields.Function(
fields.Many2One('company.company', "Company"),
'on_change_with_company')
customer = fields.Function(
fields.Many2One(
'party.party', "Customer",
context={
'company': Eval('company', -1),
}),
'on_change_with_customer', searcher='search_customer')
sale_date = fields.Function(
fields.Date("Sale Date"),
'on_change_with_sale_date', searcher='search_sale_date')

@classmethod
def get_move_product_types(cls):
Expand All @@ -1270,6 +1280,8 @@ def get_move_product_types(cls):
def __setup__(cls):
super().__setup__()
cls.__access__.add('sale')
cls._order.insert(0, ('sale.sale_date', 'DESC NULLS FIRST'))
cls._order.insert(1, ('sale.id', 'DESC'))

@classmethod
def __register__(cls, module_name):
Expand Down Expand Up @@ -1536,11 +1548,37 @@ def on_change_with_sale_state(self, name=None):
if self.sale:
return self.sale.state

@classmethod
def search_sale_state(cls, name, clause):
return [('sale.state', *clause[1:])]

@fields.depends('sale', '_parent_sale.company')
def on_change_with_company(self, name=None):
if self.sale and self.sale.company:
return self.sale.company.id

@fields.depends('sale', '_parent_sale.party')
def on_change_with_customer(self, name=None):
if self.sale and self.sale.party:
return self.sale.party.id

@classmethod
def search_customer(cls, name, clause):
return [('sale.party' + clause[0][len(name):], *clause[1:])]

@fields.depends('sale', '_parent_sale.sale_date')
def on_change_with_sale_date(self, name=None):
if self.sale:
return self.sale.sale_date

@classmethod
def search_sale_date(cls, name, clause):
return [('sale.sale_date', *clause[1:])]

@classmethod
def order_sale_date(cls, tables):
return cls.sale.convert_order('sale.sale_date', tables, cls)

def get_invoice_line(self):
'Return a list of invoice lines for sale line'
pool = Pool()
Expand Down
68 changes: 68 additions & 0 deletions modules/sale/sale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,74 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">sale_line_tree_sequence</field>
</record>

<record model="ir.action.act_window" id="act_sale_line_relate">
<field name="name">Sale Lines</field>
<field name="res_model">sale.line</field>
<field
name="domain"
eval="[('type', '=', 'line'),
If(Eval('active_model') == 'sale.sale',
('sale', 'in', Eval('active_ids', [])), ()),
If(Eval('active_model') == 'product.product',
('product', 'in', Eval('active_ids', [])), ()),
If(Eval('active_model') == 'product.template',
('product.template.id', 'in', Eval('active_ids', [])), ()),
If(Eval('active_model') == 'party.party',
('customer', 'in', Eval('active_ids', [])), ()),
]"
pyson="1"/>
</record>
<record model="ir.action.act_window.view" id="act_sale_line_relate_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="sale_line_view_tree"/>
<field name="act_window" ref="act_sale_line_relate"/>
</record>
<record model="ir.action.act_window.view" id="act_sale_line_relate_view2">
<field name="sequence" eval="20"/>
<field name="view" ref="sale_line_view_form"/>
<field name="act_window" ref="act_sale_line_relate"/>
</record>
<record model="ir.action.act_window.domain" id="act_sale_line_relate_pending">
<field name="name">Pending</field>
<field name="sequence" eval="10"/>
<field name="domain" eval="[('sale_state', 'not in', ['done', 'cancelled'])]" pyson="1"/>
<field name="count" eval="True"/>
<field name="act_window" ref="act_sale_line_relate"/>
</record>
<record model="ir.action.act_window.domain" id="act_sale_line_relate_done">
<field name="name">Done</field>
<field name="sequence" eval="20"/>
<field name="domain" eval="[('sale_state', '=', 'done')]" pyson="1"/>
<field name="count" eval="True"/>
<field name="act_window" ref="act_sale_line_relate"/>
</record>
<record model="ir.action.act_window.domain" id="act_sale_line_relate_all">
<field name="name">All</field>
<field name="sequence" eval="9999"/>
<field name="domain"></field>
<field name="act_window" ref="act_sale_line_relate"/>
</record>
<record model="ir.action.keyword" id="act_sale_line_relate_keyword_sale">
<field name="keyword">form_relate</field>
<field name="model">sale.sale,-1</field>
<field name="action" ref="act_sale_line_relate"/>
</record>
<record model="ir.action.keyword" id="act_sale_line_relate_keyword_product">
<field name="keyword">form_relate</field>
<field name="model">product.product,-1</field>
<field name="action" ref="act_sale_line_relate"/>
</record>
<record model="ir.action.keyword" id="act_sale_line_relate_keyword_product_template">
<field name="keyword">form_relate</field>
<field name="model">product.template,-1</field>
<field name="action" ref="act_sale_line_relate"/>
</record>
<record model="ir.action.keyword" id="act_sale_line_relate_keyword_party">
<field name="keyword">form_relate</field>
<field name="model">party.party,-1</field>
<field name="action" ref="act_sale_line_relate"/>
</record>

<record model="ir.ui.view" id="return_sale_start_view_form">
<field name="model">sale.return_sale.start</field>
<field name="type">form</field>
Expand Down
1 change: 1 addition & 0 deletions modules/sale/view/party_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//group[@id='links']" position="inside">
<link icon="tryton-sale" name="sale.act_sale_relate" empty="hide"/>
<link icon="tryton-sale" name="sale.act_sale_line_relate" empty="hide"/>
</xpath>
<xpath expr="/form/notebook" position="inside">
<page id="sale" string="Sale">
Expand Down
7 changes: 5 additions & 2 deletions modules/sale/view/sale_line_tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="sale" expand="1"/>
<field name="customer" expand="1" optional="0"/>
<field name="sale_date" optional="1"/>
<field name="type" optional="1"/>
<field name="product" expand="1" optional="0"/>
<field name="summary" expand="1" optional="1"/>
<field name="quantity" symbol="unit"/>
<field name="actual_quantity" symbol="unit" optional="0"/>
<field name="quantity" symbol="unit" optional="0"/>
<field name="unit_price"/>
<field name="taxes" optional="0"/>
<field name="amount"/>
<field name="sale_state"/>
</tree>
4 changes: 4 additions & 0 deletions modules/sale/view/template_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="sale_uom"/>
<label name="lead_time"/>
<field name="lead_time"/>

<group id="customers_links" col="-1" colspan="4">
<link icon="tryton-sale" name="sale.act_sale_line_relate" empty="hide"/>
</group>
</page>
</xpath>
</data>
Expand Down

0 comments on commit 84514c4

Please sign in to comment.