Allow the product code to be set by a sequence

issue8545
review261921004
This commit is contained in:
Sergi Almacellas Abellana committed 2019-08-19 11:43:26 +02:00
1 parent 9e0a46e2ce
commit 6c2512d7dc
6 files changed
+72 -6

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Allow the product code to be set by a sequence
* Allow UoM conversion between different categories
* Add product identifiers
+5
View File
@@ -26,6 +26,11 @@ class Configuration(ModelSingleton, ModelSQL, ModelView, MultiValueMixin):
default_cost_price_method = fields.MultiValue(default_cost_price_method)
get_cost_price_methods = get_cost_price_methods
product_sequence = fields.Many2One('ir.sequence', 'Product Sequence',
domain=[
('code', '=', 'product.product'),
],
help="Used to generate the product code.")
@classmethod
def default_default_cost_price_method(cls, **pattern):
+6 -4
View File
@@ -53,16 +53,18 @@ The Product Template model contains the following fields:
- Cost Price Method, which can be *Fixed* or *Average*. Defines how
the cost price should be updated. *Fixed* means that the cost price
stay unchanged. *Average* means that the cost price is the average
cost of all the items that are in stock.
cost of all the items that are in stock. It's default value can be defined
on product configuration.
- Default UOM. The default UOM for this product. Used for example to
express stock levels.
- Active, allow to disable a product.
The Product model extend the Product Template with two fields: Code
and Description. It's also possible to define a list of identifiers on product.
An identifier is composed by a type and a code. The following types are
available:
and Description. If a sequence is set on product configuration the code will
be readonly and will be filled in using the sequence. It's also possible to
define a list of identifiers on product. An identifier is composed by a type
and a code. The following types are available:
* International Article Number (EAN)
* International Standard Audiovisual Number (ISAN)
+44 -2
View File
@@ -205,8 +205,13 @@ class Product(
template = fields.Many2One('product.template', 'Product Template',
required=True, ondelete='CASCADE', select=True, states=STATES,
depends=DEPENDS)
code = fields.Char("Code", size=None, select=True, states=STATES,
depends=DEPENDS)
code_readonly = fields.Function(fields.Boolean('Code Readonly'),
'get_code_readonly')
code = fields.Char("Code", size=None, select=True,
states={
'readonly': STATES['readonly'] | Eval('code_readonly', False),
},
depends=DEPENDS + ['code_readonly'])
identifiers = fields.One2Many('product.identifier', 'product',
"Identifiers", states=STATES, depends=DEPENDS,
help="Add other identifiers to the variant.")
@@ -353,6 +358,43 @@ class Product(
icon = icon or 'tryton-product'
yield id_, rec_name, icon
@classmethod
def default_code_readonly(cls):
pool = Pool()
Configuration = pool.get('product.configuration')
config = Configuration(1)
return bool(config.product_sequence)
def get_code_readonly(self, name):
return self.default_code_readonly()
@classmethod
def _new_code(cls):
pool = Pool()
Sequence = pool.get('ir.sequence')
Configuration = pool.get('product.configuration')
config = Configuration(1)
sequence = config.product_sequence
if sequence:
return Sequence.get_id(sequence.id)
@classmethod
def create(cls, vlist):
vlist = [x.copy() for x in vlist]
for values in vlist:
if not values.get('code'):
values['code'] = cls._new_code()
return super().create(vlist)
@classmethod
def copy(cls, products, default=None):
if default is None:
default = {}
else:
default = default.copy()
default.setdefault('code', None)
return super().copy(products, default=default)
class ProductListPrice(ModelSQL, CompanyValueMixin):
"Product List Price"
+14
View File
@@ -220,6 +220,20 @@ this repository contains the full copyright notices and license terms. -->
<field name="perm_delete" eval="True"/>
</record>
<record model="ir.sequence.type" id="sequence_type_product">
<field name="name">Product</field>
<field name="code">product.product</field>
</record>
<record model="ir.sequence.type-res.group"
id="sequence_type_product_group_admin">
<field name="sequence_type" ref="sequence_type_product"/>
<field name="group" ref="res.group_admin"/>
</record>
<record model="ir.sequence.type-res.group"
id="sequence_type_product_group_product_admin">
<field name="sequence_type" ref="sequence_type_product"/>
<field name="group" ref="group_product_admin"/>
</record>
</data>
</tryton>
+2
View File
@@ -4,4 +4,6 @@ this repository contains the full copyright notices and license terms. -->
<form>
<label name="default_cost_price_method"/>
<field name="default_cost_price_method"/>
<label name="product_sequence"/>
<field name="product_sequence"/>
</form>