changeset ba2d7b9829a9 in modules/sale:default
details: https://hg.tryton.org/modules/sale?cmd=changeset;node=ba2d7b9829a9
description:
Add salable products menu entry
This shows the same product list as when selecting product from the
sale line
and provide the same contextual options.
issue8981
review258651002
diffstat:
CHANGELOG | 2 +
__init__.py | 7 +++--
product.py | 45 +++++++++++++++++++++++++++++++++++--
product.xml | 29 ++++++++++++++++++++++++
view/product_list_sale_line.xml | 2 +-
view/product_sale_context_form.xml | 19 ++++++++++++++++
6 files changed, 97 insertions(+), 7 deletions(-)
diffs (170 lines):
diff -r 52033559fc3d -r ba2d7b9829a9 CHANGELOG
--- a/CHANGELOG Wed Feb 12 00:19:27 2020 +0100
+++ b/CHANGELOG Sun Feb 23 13:55:00 2020 +0100
@@ -1,3 +1,5 @@
+* Add salable products menu entry
+
Version 5.4.0 - 2019-11-04
* Bug fixes (see mercurial logs for details)
diff -r 52033559fc3d -r ba2d7b9829a9 __init__.py
--- a/__init__.py Wed Feb 12 00:19:27 2020 +0100
+++ b/__init__.py Sun Feb 23 13:55:00 2020 +0100
@@ -3,7 +3,7 @@
from trytond.pool import Pool
from .sale import *
-from .product import *
+from . import product
from .stock import *
from .configuration import *
from .invoice import *
@@ -21,8 +21,9 @@
SaleLineTax,
SaleLineIgnoredMove,
SaleLineRecreatedMove,
- Template,
- Product,
+ product.Template,
+ product.Product,
+ product.SaleContext,
ShipmentOut,
ShipmentOutReturn,
HandleShipmentExceptionAsk,
diff -r 52033559fc3d -r ba2d7b9829a9 product.py
--- a/product.py Wed Feb 12 00:19:27 2020 +0100
+++ b/product.py Sun Feb 23 13:55:00 2020 +0100
@@ -2,14 +2,12 @@
# this repository contains the full copyright notices and license terms.
import datetime
-from trytond.model import fields
+from trytond.model import ModelView, fields
from trytond.pyson import Eval
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from trytond.modules.product import price_digits
-__all__ = ['Template', 'Product']
-
class Template(metaclass=PoolMeta):
__name__ = 'product.template'
@@ -146,3 +144,44 @@
if self.lead_time is None:
return datetime.date.max
return date + self.lead_time
+
+
+class SaleContext(ModelView):
+ "Product Sale Context"
+ __name__ = 'product.sale.context'
+
+ locations = fields.Many2Many(
+ 'stock.location', None, None, "Warehouses",
+ domain=[('type', '=', 'warehouse')])
+ company = fields.Many2One('company.company', "Company")
+ currency = fields.Many2One('currency.currency', "Currency")
+ customer = fields.Many2One('party.party', "Customer")
+ sale_date = fields.Date("Sale Date")
+ quantity = fields.Float("Quantity")
+
+ stock_date_end = fields.Function(
+ fields.Date("Stock End Date"),
+ 'on_change_with_stock_date_end')
+
+ @classmethod
+ def default_locations(cls):
+ pool = Pool()
+ Location = pool.get('stock.location')
+ return [Location.get_default_warehouse()]
+
+ @classmethod
+ def default_company(cls):
+ return Transaction().context.get('company')
+
+ @classmethod
+ def default_currency(cls):
+ pool = Pool()
+ Company = pool.get('company.company')
+ company_id = cls.default_company()
+ if company_id:
+ company = Company(company_id)
+ return company.currency.id
+
+ @fields.depends('sale_date')
+ def on_change_with_stock_date_end(self, name=None):
+ return self.sale_date
diff -r 52033559fc3d -r ba2d7b9829a9 product.xml
--- a/product.xml Wed Feb 12 00:19:27 2020 +0100
+++ b/product.xml Sun Feb 23 13:55:00 2020 +0100
@@ -9,5 +9,34 @@
<field name="priority" eval="20"/>
<field name="name">product_list_sale_line</field>
</record>
+
+ <record model="ir.action.act_window" id="act_product">
+ <field name="name">Salable Products</field>
+ <field name="res_model">product.product</field>
+ <field name="domain" eval="[('salable', '=', True)]" pyson="1"/>
+ <field name="context_model">product.sale.context</field>
+ <field name="context" eval="{'stock_skip_warehouse': True}"
pyson="1"/>
+ </record>
+ <record model="ir.action.act_window.view" id="act_product_view1">
+ <field name="sequence" eval="10"/>
+ <field name="view" ref="product_view_list_sale_line"/>
+ <field name="act_window" ref="act_product"/>
+ </record>
+ <record model="ir.action.act_window.view" id="act_product_view2">
+ <field name="sequence" eval="20"/>
+ <field name="view" ref="product.product_view_form"/>
+ <field name="act_window" ref="act_product"/>
+ </record>
+ <menuitem
+ parent="menu_sale"
+ action="act_product"
+ sequence="50"
+ id="menu_product"/>
+
+ <record model="ir.ui.view" id="product_sale_context_view_form">
+ <field name="model">product.sale.context</field>
+ <field name="type">form</field>
+ <field name="name">product_sale_context_form</field>
+ </record>
</data>
</tryton>
diff -r 52033559fc3d -r ba2d7b9829a9 view/product_list_sale_line.xml
--- a/view/product_list_sale_line.xml Wed Feb 12 00:19:27 2020 +0100
+++ b/view/product_list_sale_line.xml Sun Feb 23 13:55:00 2020 +0100
@@ -3,7 +3,7 @@
this repository contains the full copyright notices and license terms. -->
<tree>
<field name="code"/>
- <field name="name"/>
+ <field name="name" expand="1"/>
<field name="sale_price_uom"/>
<field name="list_price_uom"/>
<field name="cost_price_uom"/>
diff -r 52033559fc3d -r ba2d7b9829a9 view/product_sale_context_form.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/view/product_sale_context_form.xml Sun Feb 23 13:55:00 2020 +0100
@@ -0,0 +1,19 @@
+<?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>
+ <group colspan="2" col="4" id="fields">
+ <label name="company"/>
+ <field name="company"/>
+ <label name="currency"/>
+ <field name="currency"/>
+ <label name="sale_date"/>
+ <field name="sale_date"/>
+ <label name="quantity"/>
+ <field name="quantity"/>
+ <label name="customer"/>
+ <field name="customer"/>
+ </group>
+ <field name="locations" colspan="2" yexpand="0"/>
+ <field name="stock_date_end" invisible="1" colspan="4"/>
+</form>