Skip to content

Commit

Permalink
[MIG] product_internal_code: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-zanotti committed Jan 2, 2024
1 parent 931404f commit 86ed8c5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 32 deletions.
6 changes: 3 additions & 3 deletions product_internal_code/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{
"name": "Product Internal Code",
'version': "16.0.1.0.0",
'version': "17.0.1.0.0",
'category': 'Tools',
'sequence': 14,
'author': 'ADHOC SA',
Expand All @@ -35,11 +35,11 @@
'views/product_views.xml',
],
'demo': [
'demo/product.product.csv'
'demo/product.product.xml'
],
'test': [
],
'installable': False,
'installable': True,
'auto_install': False,
'application': False,
}
22 changes: 0 additions & 22 deletions product_internal_code/demo/product.product.csv

This file was deleted.

5 changes: 5 additions & 0 deletions product_internal_code/demo/product.product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<function model="product.product" name="_set_internal_code" eval="[obj()]"/>
</odoo>

14 changes: 8 additions & 6 deletions product_internal_code/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ class ProductProduct(models.Model):

_inherit = 'product.product'

internal_code = fields.Char(
'Internal Code', copy=False)
internal_code = fields.Char('Internal Code', copy=False, required=True)

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if (not vals.get('internal_code', False) and not self.
_context.get('default_internal_code', False)):
vals['internal_code'] = self.env[
'ir.sequence'].next_by_code('product.internal.code')
if (not vals.get('internal_code') and not self._context.get('default_internal_code')):
vals['internal_code'] = self.env['ir.sequence'].next_by_code('product.internal.code')
return super().create(vals_list)

_sql_constraints = {
('internal_code_uniq', 'unique(internal_code)',
'Internal Code mast be unique!')
}

def _set_internal_code(self):
products = self.search([('internal_code', '=', False)])
for product in products:
product.internal_code = self.env['ir.sequence'].next_by_code('product.internal.code')
2 changes: 1 addition & 1 deletion product_internal_code/views/product_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<field name="default_code" position="after">
<field name="internal_code" attrs="{'invisible': [('product_variant_count', '&gt;', 1)]}"/>
<field name="internal_code" invisible="product_variant_count &gt; 1"/>
</field>
</field>
</record>
Expand Down

0 comments on commit 86ed8c5

Please sign in to comment.