Skip to content

Commit

Permalink
[ADD] product_internal_reference_generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasProgrammer committed Oct 26, 2023
1 parent 544d165 commit 4fc2863
Show file tree
Hide file tree
Showing 18 changed files with 637 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions product_internal_reference_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions product_internal_reference_generator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Product Internal Reference Generator",
"summary": """Product template and variant reference based on sequence""",
"author": "Ilyas, Ooops, Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "https://github.com/OCA/product-variant",
"category": "Sale",
"version": "14.0.1.0.0",
"depends": ["stock"],
"data": [
"security/ir.model.access.csv",
"views/product.xml",
"security/groups.xml",
],
"installable": True,
"application": False,
}
3 changes: 3 additions & 0 deletions product_internal_reference_generator/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_code_sequence
from . import product_template
from . import product_product
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class ProductCodeSequence(models.Model):
_name = "product.code.sequence"
_description = "Internal Reference Template"

name = fields.Char(required=True)
sequence_id = fields.Many2one("ir.sequence", required=True)
variant_reference_numbers = fields.Integer(default=3, required=True)
17 changes: 17 additions & 0 deletions product_internal_reference_generator/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import api, models


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

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("product_tmpl_id"):
pt = self.env["product.template"].browse(vals["product_tmpl_id"])
if pt.variants_sequence_id:
vals["default_code"] = (

Check warning on line 13 in product_internal_reference_generator/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

product_internal_reference_generator/models/product_product.py#L13

Added line #L13 was not covered by tests
pt.variants_prefix + pt.variants_sequence_id.next_by_id()
)
res = super().create(vals_list)
return res
28 changes: 28 additions & 0 deletions product_internal_reference_generator/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

int_ref_template_id = fields.Many2one(
"product.code.sequence", "Internal Reference Template"
)
variants_sequence_id = fields.Many2one("ir.sequence")
variants_prefix = fields.Char(readonly=True, tracking=True)

@api.onchange("int_ref_template_id")
def onchange_int_ref_template_id(self):
self.variants_prefix = False

Check warning on line 15 in product_internal_reference_generator/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_internal_reference_generator/models/product_template.py#L15

Added line #L15 was not covered by tests

def btn_generate_sequence(self):
self.ensure_one()
int_ref_next_val = self.int_ref_template_id.sequence_id.next_by_id()
self.variants_prefix = int_ref_next_val
var_seq = self.env["ir.sequence"].create(

Check warning on line 21 in product_internal_reference_generator/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_internal_reference_generator/models/product_template.py#L18-L21

Added lines #L18 - L21 were not covered by tests
{
"name": "variants " + int_ref_next_val,
"padding": self.int_ref_template_id.variant_reference_numbers,
}
)
self.variants_sequence_id = var_seq
self.default_code = int_ref_next_val + var_seq.get_next_char(0)

Check warning on line 28 in product_internal_reference_generator/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_internal_reference_generator/models/product_template.py#L27-L28

Added lines #L27 - L28 were not covered by tests
Empty file.
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions product_internal_reference_generator/security/groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="group_int_ref_template_always_visible" model="res.groups">
<field name="name">Internal reference template always visible</field>
<field name="category_id" ref="base.module_category_hidden" />
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
pcs1,pcs1,model_product_code_sequence,base.group_user,1,1,0,0
pcs2,pcs2,model_product_code_sequence,base.group_system,1,1,1,1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4fc2863

Please sign in to comment.