-
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] product_internal_reference_generator
- Loading branch information
1 parent
544d165
commit 096e10a
Showing
19 changed files
with
699 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"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", | ||
], | ||
"demo": ["demo/demo.xml"], | ||
"installable": True, | ||
"application": False, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version='1.0' encoding='utf-8' ?> | ||
<odoo> | ||
|
||
<record model="ir.sequence" id="demo_pcs_seq_1"> | ||
<field name="name">Good products sequence</field> | ||
<field name="prefix">GOOD</field> | ||
<field name="padding">4</field> | ||
</record> | ||
|
||
<record model="ir.sequence" id="demo_pcs_seq_2"> | ||
<field name="name">Bad products sequence</field> | ||
<field name="prefix">BAD</field> | ||
<field name="padding">5</field> | ||
</record> | ||
|
||
<record model="product.code.sequence" id="demo_pcs_1"> | ||
<field name="name">Good products</field> | ||
<field name="variant_reference_numbers">3</field> | ||
<field | ||
name="sequence_id" | ||
ref="product_internal_reference_generator.demo_pcs_seq_1" | ||
/> | ||
</record> | ||
|
||
<record model="product.code.sequence" id="demo_pcs_2"> | ||
<field name="name">Bad products</field> | ||
<field name="variant_reference_numbers">4</field> | ||
<field | ||
name="sequence_id" | ||
ref="product_internal_reference_generator.demo_pcs_seq_2" | ||
/> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
10 changes: 10 additions & 0 deletions
10
product_internal_reference_generator/models/product_code_sequence.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("Digits", default=3, required=True) |
17 changes: 17 additions & 0 deletions
17
product_internal_reference_generator/models/product_product.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] = ( | ||
pt.variants_prefix + pt.variants_sequence_id.next_by_id() | ||
) | ||
res = super().create(vals_list) | ||
return res |
30 changes: 30 additions & 0 deletions
30
product_internal_reference_generator/models/product_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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( | ||
"Internal Reference Prefix", readonly=True, tracking=True | ||
) | ||
|
||
@api.onchange("int_ref_template_id") | ||
def onchange_int_ref_template_id(self): | ||
self.variants_prefix = False | ||
|
||
def btn_generate_sequence(self): | ||
self.ensure_one() | ||
self.variants_prefix = self.int_ref_template_id.sequence_id.get_next_char(0) | ||
int_ref_next_val = self.int_ref_template_id.sequence_id.next_by_id() | ||
var_seq = self.env["ir.sequence"].create( | ||
{ | ||
"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) | ||
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
3 changes: 3 additions & 0 deletions
3
product_internal_reference_generator/security/ir.model.access.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.