Skip to content

Commit

Permalink
product_sequence
Browse files Browse the repository at this point in the history
Add pre_init_hook to manually set nulls and '/' default codes
 to a unique code to greenify branch
add pragma to pre_init method as it must have completed successfully
if module installs
  • Loading branch information
gdgellatly authored and dc-oerp committed Jul 19, 2024
1 parent 941b5b1 commit a0c86c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions product_sequence/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
'data': [
'data/product_sequence.xml',
],
'demo': [
'demo/product_product.xml'
],
'pre_init_hook': 'update_null_and_slash_codes',
'auto_install': False,
'installable': True,
}
16 changes: 16 additions & 0 deletions product_sequence/demo/product_product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="product.product_product_consultant" model="product.product">
<field name="default_code">SERVICE</field>
</record>

<record id="product.product_product_1" model="product.product">
<field name="default_code">OSM</field>
</record>

<record id="product.product_product_2" model="product.product">
<field name="default_code">OSA</field>
</record>
</data>
</openerp>
13 changes: 13 additions & 0 deletions product_sequence/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
from odoo import _, api, fields, models


def update_null_and_slash_codes(cr): # pragma: no cover
"""
Updates existing codes matching the default '/' or
empty. Primarily this ensures installation does not
fail for demo data.
:param cr: database cursor
:return: void
"""
cr.execute("UPDATE product_product "
"SET default_code = '!!mig!!' || id "
"WHERE default_code IS NULL OR default_code = '/';")


class ProductProduct(models.Model):
_inherit = "product.product"

Expand Down

0 comments on commit a0c86c3

Please sign in to comment.