Skip to content

Commit

Permalink
Merge b9bfe14 into da3e482
Browse files Browse the repository at this point in the history
  • Loading branch information
ahilali committed Jun 2, 2015
2 parents da3e482 + b9bfe14 commit 9e57977
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 0 deletions.
1 change: 1 addition & 0 deletions product_attribute_code/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product
36 changes: 36 additions & 0 deletions product_attribute_code/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# Module for OpenERP
# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved
# @author Benoît GUILLOT <benoit.guillot@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

{
'name': 'Product Attribute Code',
'version': '0.1',
'category': 'Generic Modules/Others',
'license': 'AGPL-3',
'author': 'Akretion',
'website': 'http://www.akretion.com/',
'depends': ['product'],
'data': [
'product_view.xml',
],
'demo': [],
'installable': True,
}
43 changes: 43 additions & 0 deletions product_attribute_code/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_attribute_code
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-05-29 09:00+0000\n"
"PO-Revision-Date: 2015-05-29 11:45+0100\n"
"Last-Translator: Abdessamad HILALI <abdessamad.hilali@akretion.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
"Language: Français\n"

#. module: product_attribute_code
#: field:product.attribute,code:0 field:product.attribute.value,code:0
msgid "Code"
msgstr "Code"

#. module: product_attribute_code
#: field:product.attribute.value,comment:0
msgid "Comment"
msgstr "Commentaire"

#. module: product_attribute_code
#: model:ir.model,name:product_attribute_code.model_product_attribute
msgid "Product Attribute"
msgstr "L'attribut du produit"

#. module: product_attribute_code
#: field:product.attribute.value,readonly:0
msgid "Readonly"
msgstr "Lecture seule"

#. module: product_attribute_code
#: field:product.attribute,sequence:0
msgid "Sequence"
msgstr "Séquence"

43 changes: 43 additions & 0 deletions product_attribute_code/i18n/product_attribute_code.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * product_attribute_code
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-05-29 09:00+0000\n"
"PO-Revision-Date: 2015-05-29 09:00+0000\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_attribute_code
#: field:product.attribute,code:0
#: field:product.attribute.value,code:0
msgid "Code"
msgstr ""

#. module: product_attribute_code
#: field:product.attribute.value,comment:0
msgid "Comment"
msgstr ""

#. module: product_attribute_code
#: model:ir.model,name:product_attribute_code.model_product_attribute
msgid "Product Attribute"
msgstr ""

#. module: product_attribute_code
#: field:product.attribute.value,readonly:0
msgid "Readonly"
msgstr ""

#. module: product_attribute_code
#: field:product.attribute,sequence:0
msgid "Sequence"
msgstr ""

50 changes: 50 additions & 0 deletions product_attribute_code/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# Module for OpenERP
# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved
# @author Benoît GUILLOT <benoit.guillot@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

from openerp import fields, models


class ProductAttribute(models.Model):
_inherit = "product.attribute"

code = fields.Char('Code')
sequence = fields.Integer('Sequence')

_sql_constraints = [
('attr_code_uniq', 'unique(code)',
"With each Attribute we must be found a unique 'code'"),
]


class ProductAttributeValue(models.Model):
_inherit = "product.attribute.value"

code = fields.Char('Code')
comment = fields.Text('Comment')
readonly = fields.Boolean(
help="This is an invisible field it allows us to control code and"
"comment fields")

_sql_constraints = [
('attr_val_code_uniq', 'unique(code, attribute_id)',
"With each Attribute we must be found a unique 'code'"),
]
47 changes: 47 additions & 0 deletions product_attribute_code/product_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Module for OpenERP
Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved
@author Benoît GUILLOT <benoit.guillot@akretion.com>
The licence is in the file __openerp__.py
-->

<openerp>
<data>
<!-- INHERITED VIEW FOR THE OBJECT : product_attribute -->

<record id="attr_tree_view" model="ir.ui.view">
<field name="name">product_attribute_code.attribute.tree</field>
<field name="model">product.attribute</field>
<field name="inherit_id" ref="product.attribute_tree_view"/>
<field name="arch" type="xml">
<field name="name" position="before">
<field name="sequence"/>
</field>
<field name="name" position="after">
<field name="code"/>
</field>
</field>
</record>


<!-- INHERITED VIEW FOR THE OBJECT : product_attr_value -->

<record id="variants_tree_view" model="ir.ui.view">
<field name="name">code.product.attribute.value.tree</field>
<field name="model">product.attribute.value</field>
<field name="inherit_id" ref="product.variants_tree_view"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="code"
attrs="{'readonly': [('readonly', '=', True)]}"/>
<field name="comment"
attrs="{'readonly': [('readonly', '=', True)]}"/>
<field name="readonly" invisible="1"/>
</field>
</field>
</record>


</data>
</openerp>
40 changes: 40 additions & 0 deletions product_attribute_global_item_code/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

Product Attribute Global Item Code
==================================

This module was written to automatically create default_code using a base code

For example :


.. image:: img/img_1.png


with our module we can create code of T-shirt in the form : Tsh_Co-Bl_Si-XL


.. image:: img/img_0.png


Contributors
------------

* Benoît GUILLOT <benoit.guillot@akretion.com>
* Abdessamad HILALI <abdessamad.hilali@akretion.com>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://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 http://odoo-community.org.
2 changes: 2 additions & 0 deletions product_attribute_global_item_code/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

from . import product
35 changes: 35 additions & 0 deletions product_attribute_global_item_code/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) All Rights Reserved 2015 Akretion
# @author Abdessamad HILALI <abdessamad.hilali@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

{
'name': "Product",
'author': "Akretion,Odoo Community Association (OCA)",
'website': "http://www.Akretion.com",
'license': 'AGPL-3',
'category': 'Product',
'version': '0.1',
'depends': ['product', 'product_attribute_code'],
'data': [
'product_view.xml'
],
'demo': [
],
}
Binary file added product_attribute_global_item_code/img/img_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added product_attribute_global_item_code/img/img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions product_attribute_global_item_code/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# Copyright (C) 2015 Akretion (http://www.akretion.com). All Rights Reserved
# @author Abdessamad HILALI <abdessamad.hilali@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################

from openerp import fields, models, api, _
from openerp.exceptions import Warning


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

base_code = fields.Char('Base Code',
help="this field is used as a base "
"for automatically create "
"Internal Reference(default_code)")


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

use_internal_ref = fields.Boolean('Manual Internal Reference',
default=False)
manual_default_code = fields.Char(
help="This is an invisible field used to store default_code value"
)
default_code = fields.Char(compute="_compute_default_code",
inverse="_set_manual_default_code",
store=True)

@api.multi
def _build_code(self, vals):
""""inherit this method to customize your own behavior"""
self.ensure_one()
return "".join([self.base_code] + ["".join(val) for val in vals])

@api.multi
def _get_default_code(self):
self.ensure_one()
vals = []
for value in self.attribute_value_ids:
if not value.attribute_id.code:
raise Warning(
_("Missing code for %s to correct this error you must "
"see :Configuration -> Product Categories -> Attribute")
% (value.attribute_id.name))
if not value.code:
raise Warning(
_("Missing code for %s to correct this error you must "
"see :Configuration -> Product Categories -> "
"Attribute Value exactly in %s")
% (value.name, value.attribute_id.name))
vals.append((value.attribute_id.code, value.code))
return self._build_code(vals)

def _set_manual_default_code(self):
self.manual_default_code = self.default_code

@api.depends('use_internal_ref',
'attribute_value_ids.attribute_id.code',
'attribute_value_ids.code',
'manual_default_code')
@api.one
def _compute_default_code(self):
if not self.use_internal_ref:
self.default_code = self._get_default_code()
else:
self.default_code = self.manual_default_code
Loading

0 comments on commit 9e57977

Please sign in to comment.