Skip to content

Commit

Permalink
Merge PR #1453 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Nov 24, 2023
2 parents 743be98 + b028717 commit da7b4ab
Show file tree
Hide file tree
Showing 22 changed files with 976 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ odoo_test_flavor: Both
odoo_version: 14.0
org_name: Odoo Community Association (OCA)
org_slug: OCA
rebel_module_groups: []
rebel_module_groups:
- product_internal_reference_generator
repo_description: 'TODO: add repo description.'
repo_name: product-attribute
repo_slug: product-attribute
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ jobs:
matrix:
include:
- container: ghcr.io/oca/oca-ci/py3.6-odoo14.0:latest
include: "product_internal_reference_generator"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.6-ocb14.0:latest
include: "product_internal_reference_generator"
name: test with OCB
makepot: "true"
- container: ghcr.io/oca/oca-ci/py3.6-odoo14.0:latest
exclude: "product_internal_reference_generator"
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.6-ocb14.0:latest
exclude: "product_internal_reference_generator"
name: test with OCB
makepot: "true"
services:
Expand All @@ -49,6 +58,9 @@ jobs:
POSTGRES_DB: odoo
ports:
- 5432:5432
env:
INCLUDE: "${{ matrix.include }}"
EXCLUDE: "${{ matrix.exclude }}"
steps:
- uses: actions/checkout@v3
with:
Expand Down
119 changes: 119 additions & 0 deletions product_internal_reference_generator/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
====================================
Product Internal Reference Generator
====================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:3044a39b233283158fdc8a459f7951b1e03a2eb8626bf7ef85fb11d5c1266b8e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github
:target: https://github.com/OCA/product-attribute/tree/14.0/product_internal_reference_generator
:alt: OCA/product-attribute
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/product-attribute-14-0/product-attribute-14-0-product_internal_reference_generator
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to generate internal references for Product templates and variants using sequences, setting codes as read-only.

In product template, it's possible to choose among different Internal Reference Templates related to a sequence, and then generate an internal reference with the following structure:

Internal Reference Prefix + progressive number for variant, eg: “Main0001001”, where:

"Main0001" is the prefix generated by sequence and assigned to product template, and

"001" the variant identifier.


Every time a new variant is created, a new internal reference is automatically assigned with progressive variant code.


A specific access rights allows specific users to change internal reference template for a product template once an internal reference has been generated, as well as editing existing ones.

**Table of contents**

.. contents::
:local:

Usage
=====

Go to inventory > Configuration > Internal Reference Templates and set:

the sequence to be used for Internal Reference Prefix generation

the number of digits to be used for variants code (standard is 3)

Now go to product template, select an Internal Reference Template and generate an Internal Reference Prefix. Internal reference field is now read-only.

Each time a new variant is created for this product template, an internal reference is automatically assigned.

Known issues / Roadmap
======================

Due to odoo's behavior in handling internal reference for variants (see for example https://github.com/odoo/odoo/issues/140356 ), removing all attributes from a product template with variants will generate a new internal reference for product template.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_internal_reference_generator%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Ilyas
* Ooops

Contributors
~~~~~~~~~~~~

* `Ooops404 <https://www.ooops404.com>`__:

* Ilyas <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-ilyasProgrammer| image:: https://github.com/ilyasProgrammer.png?size=40px
:target: https://github.com/ilyasProgrammer
:alt: ilyasProgrammer

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ilyasProgrammer|

This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/14.0/product_internal_reference_generator>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
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
19 changes: 19 additions & 0 deletions product_internal_reference_generator/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Product Internal Reference Generator",
"summary": """Product template and variant reference based on sequence""",
"author": "Ilyas, Ooops, Odoo Community Association (OCA)",
"maintainers": ["ilyasProgrammer"],
"license": "AGPL-3",
"website": "https://github.com/OCA/product-attribute",
"category": "Sale",
"version": "14.0.1.0.0",
"depends": ["stock", "base_view_inheritance_extension"],
"data": [
"security/groups.xml",
"security/ir.model.access.csv",
"views/product.xml",
],
"demo": ["demo/product_code_seq_demo.xml"],
"installable": True,
"application": False,
}
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>
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,12 @@
# Copyright 2023 Ooops - Ilyas
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
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)
16 changes: 16 additions & 0 deletions product_internal_reference_generator/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 Ooops - Ilyas
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
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.get_variant_next_default_code()
return super().create(vals_list)
46 changes: 46 additions & 0 deletions product_internal_reference_generator/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2023 Ooops - Ilyas
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
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()
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.write(
{
"variants_prefix": int_ref_next_val,
"variants_sequence_id": var_seq.id,
"default_code": int_ref_next_val + var_seq.get_next_char(0),
}
)
self.update_variants_default_code()

def update_variants_default_code(self):
for pp in self.product_variant_ids.filtered(lambda p: not p.default_code):
pp.default_code = self.get_variant_next_default_code()

def get_variant_next_default_code(self):
if self.variants_sequence_id:
return self.variants_prefix + self.variants_sequence_id.next_by_id()
return False
3 changes: 3 additions & 0 deletions product_internal_reference_generator/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Ooops404 <https://www.ooops404.com>`__:

* Ilyas <[email protected]>
15 changes: 15 additions & 0 deletions product_internal_reference_generator/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This module allows to generate internal references for Product templates and variants using sequences, setting codes as read-only.

In product template, it's possible to choose among different Internal Reference Templates related to a sequence, and then generate an internal reference with the following structure:

Internal Reference Prefix + progressive number for variant, eg: “Main0001001”, where:

"Main0001" is the prefix generated by sequence and assigned to product template, and

"001" the variant identifier.


Every time a new variant is created, a new internal reference is automatically assigned with progressive variant code.


A specific access rights allows specific users to change internal reference template for a product template once an internal reference has been generated, as well as editing existing ones.
1 change: 1 addition & 0 deletions product_internal_reference_generator/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Due to odoo's behavior in handling internal reference for variants (see for example https://github.com/odoo/odoo/issues/140356 ), removing all attributes from a product template with variants will generate a new internal reference for product template.
9 changes: 9 additions & 0 deletions product_internal_reference_generator/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Go to inventory > Configuration > Internal Reference Templates and set:

the sequence to be used for Internal Reference Prefix generation

the number of digits to be used for variants code (standard is 3)

Now go to product template, select an Internal Reference Template and generate an Internal Reference Prefix. Internal reference field is now read-only.

Each time a new variant is created for this product template, an internal reference is automatically assigned.
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

0 comments on commit da7b4ab

Please sign in to comment.