-
-
Notifications
You must be signed in to change notification settings - Fork 720
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by simahawk
- Loading branch information
Showing
14 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
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,67 @@ | ||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
====================== | ||
Product Code Mandatory | ||
====================== | ||
|
||
This module sets the field internal reference (default_code) of the product | ||
as required. | ||
|
||
Usage | ||
===== | ||
|
||
* Unable to save a product with an empty or blank internal reference. | ||
* When creating more than one product variant from the template, a variant will be created | ||
with a default value for default_code field. | ||
* A pre_init_hook process is initiated when there exist records without an internal reference(default_code). | ||
A default value is generated to populate empty field as a temporary value. | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/135/12.0 | ||
|
||
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 smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Antonio Yamuta <ayamuta@opensourceintegrators.com> | ||
* Sudhir Arya <sudhir@erpharbor.com> | ||
|
||
Funders | ||
------- | ||
|
||
The development of this module has been financially supported by: | ||
|
||
* Open Source Integrators <http://www.opensourceintegrators.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
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. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
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,13 @@ | ||
from . import models | ||
|
||
|
||
def pre_init_product_code(cr): | ||
cr.execute("""UPDATE product_template | ||
SET default_code = 'DEFAULT' || nextval('ir_default_id_seq') | ||
WHERE default_code is NULL | ||
OR LENGTH(default_code) = 0""") | ||
cr.execute("""UPDATE product_product | ||
SET default_code = 'DEFAULT' || nextval('ir_default_id_seq') | ||
WHERE default_code is NULL | ||
OR LENGTH(default_code) = 0""") | ||
return True |
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,21 @@ | ||
# Copyright (C) 2018 - TODAY, Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Product Internal Reference as Required", | ||
"summary": "Set Product Internal Reference as a required field", | ||
"version": "12.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "Open Source Integrators, Odoo Community Association (OCA)", | ||
"category": "Product", | ||
"website": "https://github.com/OCA/product-attribute", | ||
"depends": [ | ||
"product", | ||
], | ||
"data": [ | ||
"data/product_code_seq.xml", | ||
"views/product_view.xml", | ||
], | ||
"pre_init_hook": 'pre_init_product_code', | ||
"installable": True, | ||
} |
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,12 @@ | ||
<?xml version="1.0"?> | ||
<odoo noupdate="1"> | ||
|
||
<record id="product_default_code_seq" model="ir.sequence"> | ||
<field name="name">Product Default Code Mandatory</field> | ||
<field name="code">product.default.code</field> | ||
<field name="prefix">DEFAULT-</field> | ||
<field name="padding">4</field> | ||
<field name="company_id" eval="False"/> | ||
</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,20 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * product_code_mandatory | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: product_code_mandatory | ||
#: model:ir.model,name:product_code_mandatory.model_product_product | ||
msgid "Product" | ||
msgstr "" | ||
|
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 product |
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,14 @@ | ||
# Copyright (C) 2018 - TODAY, Open Source Integrators License AGPL-3.0 | ||
# or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = 'product.product' | ||
|
||
def _get_default_code(self): | ||
return self.env['ir.sequence'].next_by_code('product.default.code') | ||
|
||
default_code = fields.Char('Internal Reference', index=True, | ||
default=_get_default_code) |
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,2 @@ | ||
* Antonio Yamuta <ayamuta@opensourceintegrators.com> | ||
* Sudhir Arya <sudhir@erpharbor.com> |
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,2 @@ | ||
This module sets the field internal reference (default_code) of the product | ||
as required. |
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,9 @@ | ||
* Unable to save a product with an empty or blank internal reference. | ||
* When creating more than one product variant from the template, a variant will be created | ||
with a default value for default_code field. | ||
* A pre_init_hook process is initiated when there exist records without an internal reference(default_code). | ||
A default value is generated to populate empty field as a temporary value. | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/135/12.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 test_product_code |
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 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestProductCode(TransactionCase): | ||
|
||
def setUp(self): | ||
super(TestProductCode, self).setUp() | ||
self.product_model = self.env['product.product'] | ||
self.product = self.product_model.create({ | ||
'name': 'Test Product Code', | ||
}) | ||
|
||
def test_product_code(self): | ||
"""Check Product Code""" | ||
self.assertTrue(self.product.default_code, 'Product code is not set.') |
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,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
|
||
<record id="product_template_only_form_code_mandatory_view" model="ir.ui.view"> | ||
<field name="name">product.template.only.form.code.mandatory.view</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="product.product_template_only_form_view"/> | ||
<field name="arch" type="xml"> | ||
<field name="default_code" position="attributes"> | ||
<attribute name="attrs">{'invisible': [('product_variant_count', '>', 1)], | ||
'required': [('product_variant_count', '=', 1)]}</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="product_normal_form_code_mandatory_view" model="ir.ui.view"> | ||
<field name="name">product.normal.form.code.mandatory.view</field> | ||
<field name="model">product.product</field> | ||
<field name="inherit_id" ref="product.product_normal_form_view"/> | ||
<field name="arch" type="xml"> | ||
<field name="default_code" position="attributes"> | ||
<attribute name="required">True</attribute> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |