diff --git a/product_customer_code/README.rst b/product_customer_code/README.rst new file mode 100644 index 00000000000..25a5b5002a8 --- /dev/null +++ b/product_customer_code/README.rst @@ -0,0 +1,78 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +====================== +Products Customer Code +====================== + +This module does just like the product.supplierinfo but for customers instead. For instance it +allows to have different references for the same product according to the customer. + +.. figure:: static/src/img/screenshot1.png + :alt: alternative description + :width: 600 px + +.. tip:: + + You will need install some of the Apps which enable the product menu to see this module in + action, like Sales, Purchase or Warehouse Management + +Installation +============ + +To install this module, you need to: + +1. Clone the branch 8.0 of the repository https://github.com/OCA/product-attribute +2. Add the path to this repository in your configuration (addons-path) +3. Update the module list +4. Go to menu *Setting -> Modules -> Local Modules* +5. Search For *Products Customer Code* +6. Install the module + +Usage +===== + +.. 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/8.0 + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Hurrinico +* OpenSynergy Indonesia +* Michael Viriyananda + +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. diff --git a/product_customer_code/__init__.py b/product_customer_code/__init__.py index df5910868b4..c3fd553c6a0 100644 --- a/product_customer_code/__init__.py +++ b/product_customer_code/__init__.py @@ -1,2 +1,6 @@ -import product_customer_code -import product +# -*- coding: utf-8 -*- +# © 2014 Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models +from . import tests diff --git a/product_customer_code/__openerp__.py b/product_customer_code/__openerp__.py index af8cd13e819..677d059ca36 100644 --- a/product_customer_code/__openerp__.py +++ b/product_customer_code/__openerp__.py @@ -1,60 +1,21 @@ -# -*- encoding: utf-8 -*- -########################################################################### -# Module Writen to OpenERP, Open Source Management Solution -# -# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com/ -# All Rights Reserved. -# info Vauxoo (info@vauxoo.com) -############################################################################ -# Coded by: el_rodo_1 (rodo@vauxoo.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 . -# -############################################################################## -{ - "name": "Products Customer Code", - "version": "1.0", - "author": "Vauxoo,Odoo Community Association (OCA)", - "website": "http://www.vauxoo.com/", - "license": "AGPL-3", - "category": "Generic Modules/Product", - "summary": "Add many Customers' Codes in product", - "depends": [ - "base", - "product", - ], - "description": """ -Customer' codes in product -========================== - -This module does just like the product.supplierinfo but for customers instead. For instance it -allows to have different references for the same product according to the customer. +# -*- coding: utf-8 -*- +# © 2014 Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -.. image:: product_customer_code/static/src/img/screenshot1.png - -.. tip:: - - You will need install some of the Apps which enable the product menu to see this module in - action, like Sales, Purchase or Warehouse Management - """, - "data": [ - "security/product_customer_code_security.xml", - "security/ir.model.access.csv", - "product_customer_code_view.xml", - "product_product_view.xml", +{ + 'name': 'Products Customer Code', + 'version': '8.0.1.0.0', + 'summary': 'Add many Customers Codes in product', + 'author': 'Vauxoo,Odoo Community Association (OCA)', + 'website': 'http://www.vauxoo.com/', + 'category': 'Generic Modules/Product', + 'depends': ['base', 'product'], + 'data': [ + 'security/product_customer_code_security.xml', + 'security/ir.model.access.csv', + 'views/product_customer_code_view.xml', + 'views/product_product_view.xml', ], - "active": False, - 'installable': False, + 'installable': True, + 'license': 'AGPL-3', } diff --git a/product_customer_code/models/__init__.py b/product_customer_code/models/__init__.py new file mode 100644 index 00000000000..69d00e818ec --- /dev/null +++ b/product_customer_code/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2014 Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import product_customer_code +from . import product diff --git a/product_customer_code/models/product.py b/product_customer_code/models/product.py new file mode 100644 index 00000000000..a55465492a8 --- /dev/null +++ b/product_customer_code/models/product.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# © 2014 Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + product_customer_code_ids = fields.One2many( + string='Customer Codes', + comodel_name='product.customer.code', + inverse_name='product_id' + ) + + @api.multi + def copy(self, default=None): + if not default: + default = {} + default['product_customer_code_ids'] = False + return super(ProductProduct, self.with_context(copy=True))\ + .copy(default) + + def name_search(self, cr, user, name='', args=None, operator='ilike', + context=None, limit=80): + res = super(ProductProduct, self).name_search( + cr, user, name, args, operator, context, limit) + if not context: + context = {} + product_customer_code_obj = self.pool.get('product.customer.code') + if not res: + ids = [] + partner_id = context.get('partner_id', False) + if partner_id: + id_prod_code = \ + product_customer_code_obj.search(cr, user, + [('product_code', + '=', name), + ('partner_id', '=', + partner_id)], + limit=limit, + context=context) + # TODO: Search for product customer name + id_prod = id_prod_code and product_customer_code_obj.browse( + cr, user, id_prod_code, context=context) or [] + for ppu in id_prod: + ids.append(ppu.product_id.id) + if ids: + res = self.name_get(cr, user, ids, context) + return res diff --git a/product_customer_code/models/product_customer_code.py b/product_customer_code/models/product_customer_code.py new file mode 100644 index 00000000000..f4c3cbd1294 --- /dev/null +++ b/product_customer_code/models/product_customer_code.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# © 2014 Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields + + +class ProductCustomerCode(models.Model): + _name = "product.customer.code" + _description = "Add manies Code of Customer's" + + product_name = fields.Char(string='Customer Product Name', + help="""This customer's product name will + be used when searching into a + request for quotation.""") + product_code = fields.Char(string='Customer Product Code', + help="""This customer's product code + will be used when searching into + a request for quotation.""") + product_id = fields.Many2one(comodel_name='product.product', + string='Product', required=True) + partner_id = fields.Many2one(comodel_name='res.partner', string='Customer', + required=True) + company_id = fields.Many2one( + comodel_name='res.company', string='Company', required=False, + default=lambda self: self.env['res.company']._company_default_get( + 'product.customer.code')) diff --git a/product_customer_code/product.py b/product_customer_code/product.py deleted file mode 100644 index 350a66f23db..00000000000 --- a/product_customer_code/product.py +++ /dev/null @@ -1,73 +0,0 @@ -# -*- coding: utf-8 -*- -########################################################################### -# Module Writen to OpenERP, Open Source Management Solution -# -# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com -# All Rights Reserved. -# info@vauxoo.com -############################################################################ -# Coded by: Rodo (rodo@vauxoo.com),Moy (moylop260@vauxoo.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 . -# -############################################################################## -from openerp.osv import orm, fields -from openerp.tools.translate import _ - - -class product_product(orm.Model): - _inherit = "product.product" - - _columns = { - 'product_customer_code_ids': fields.one2many('product.customer.code', - 'product_id', - 'Customer Codes'), - } - - def copy(self, cr, uid, id, default=None, context=None): - if not default: - default = {} - default['product_customer_code_ids'] = False - res = super(product_product, self).copy( - cr, uid, id, default=default, context=context) - return res - - def name_search(self, cr, user, name='', args=None, operator='ilike', - context=None, limit=80): - res = super(product_product, self).name_search( - cr, user, name, args, operator, context, limit) - if not context: - context = {} - product_customer_code_obj = self.pool.get('product.customer.code') - if not res: - ids = [] - partner_id = context.get('partner_id', False) - if partner_id: - id_prod_code = \ - product_customer_code_obj.search(cr, user, - [('product_code', - '=', name), - ('partner_id', '=', - partner_id)], - limit=limit, - context=context) - # TODO: Search for product customer name - id_prod = id_prod_code and product_customer_code_obj.browse( - cr, user, id_prod_code, context=context) or [] - for ppu in id_prod: - ids.append(ppu.product_id.id) - if ids: - res = self.name_get(cr, user, ids, context) - return res diff --git a/product_customer_code/product_customer_code.py b/product_customer_code/product_customer_code.py deleted file mode 100644 index d3593891a20..00000000000 --- a/product_customer_code/product_customer_code.py +++ /dev/null @@ -1,67 +0,0 @@ -# -*- coding: utf-8 -*- -########################################################################### -# Module Writen to OpenERP, Open Source Management Solution -# -# Copyright (c) 2012 Vauxoo - http://www.vauxoo.com -# All Rights Reserved. -# info@vauxoo.com -############################################################################ -# Coded by: Rodo (rodo@vauxoo.com),Moy (moylop260@vauxoo.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 . -# -############################################################################## -from openerp.osv import orm, fields -from openerp.tools.translate import _ - - -class product_customer_code(orm.Model): - _name = "product.customer.code" - _description = "Add manies Code of Customer's" - - _rec_name = 'product_code' - - _columns = { - 'product_code': fields.char('Customer Product Code', size=64, - required=True, - help="""This customer's product code - will be used when searching into - a request for quotation."""), - 'product_name': fields.char('Customer Product Name', size=128, - help="""This customer's product name will - be used when searching into a - request for quotation."""), - 'product_id': fields.many2one('product.product', 'Product', - required=True), - 'partner_id': fields.many2one('res.partner', 'Customer', - required=True), - 'company_id': fields.many2one('res.company', 'Company', - required=False), - } - - _defaults = { - 'company_id': lambda s, cr, - uid, c: s.pool.get('res.company'). - _company_default_get(cr, uid, - 'product.customer.code', - context=c), - } - - _sql_constraints = [ - ('unique_code', 'unique(product_code,company_id,partner_id)', - 'Product Code of customer must be unique'), - ] - - # TODO: Add index to product_code, partner_id diff --git a/product_customer_code/static/description/icon.png b/product_customer_code/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/product_customer_code/static/description/icon.png differ diff --git a/product_customer_code/tests/__init__.py b/product_customer_code/tests/__init__.py new file mode 100644 index 00000000000..7c47b606f9d --- /dev/null +++ b/product_customer_code/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2014 Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_copy +from . import test_name_search diff --git a/product_customer_code/tests/test_copy.py b/product_customer_code/tests/test_copy.py new file mode 100644 index 00000000000..7e7d50d4ee4 --- /dev/null +++ b/product_customer_code/tests/test_copy.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# © 2014 Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase + + +class ProductCaseCopy(TransactionCase): + def setUp(self, *args, **kwargs): + super(ProductCaseCopy, self).setUp(*args, **kwargs) + # Data Products + self.prod = self.env.ref('product.product_product_5') + + def test_copy(self): + prod_copy = self.prod.copy() + self.assertFalse(prod_copy.product_customer_code_ids) diff --git a/product_customer_code/tests/test_name_search.py b/product_customer_code/tests/test_name_search.py new file mode 100644 index 00000000000..198cf2ba2ce --- /dev/null +++ b/product_customer_code/tests/test_name_search.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +# © 2014 Acsone SA/NV (http://www.acsone.eu) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase + + +class ProductCaseNameSearch(TransactionCase): + def setUp(self, *args, **kwargs): + super(ProductCaseNameSearch, self).setUp(*args, **kwargs) + # Objects + self.obj_product = self.env['product.product'] + + # Data Category Product + self.categ = self.ref('product.accessories') + + # Data UOM + self.uom = self.ref('product.product_uom_unit') + + # Data Partner + self.partner = self.ref('base.res_partner_3') + + def _prepare_product_data(self): + data = { + 'name': 'Test Product - 1', + 'categ_id': self.categ, + 'standard_price': 500.0, + 'list_price': 150.5, + 'type': 'consu', + 'uom_id': self.uom, + 'uom_po_id': self.uom, + 'default_code': 'TST001', + 'product_customer_code_ids': [ + (0, 0, {'product_name': 'Test Product - 1', + 'product_code': 'CUST001', + 'partner_id': self.partner}) + ] + } + + return data + + def _create_product(self): + data = self._prepare_product_data() + product = self.obj_product.create(data) + + return product + + def test_name_search(self): + prod_id = self._create_product().id + # Check Create Product + self.assertIsNotNone(prod_id) + + # Check Name Search + self.prod_ids = [prod_id] + search_ids = self.obj_product.with_context(partner_id=self.partner).\ + name_search( + name="CUST001", + operator='ilike', + args=[('id', 'in', self.prod_ids)]) + self.assertEqual(set([prod_id]), set([a[0] for a in search_ids])) diff --git a/product_customer_code/product_customer_code_view.xml b/product_customer_code/views/product_customer_code_view.xml similarity index 83% rename from product_customer_code/product_customer_code_view.xml rename to product_customer_code/views/product_customer_code_view.xml index 0fddfd30f01..dcb2d243c3e 100644 --- a/product_customer_code/product_customer_code_view.xml +++ b/product_customer_code/views/product_customer_code_view.xml @@ -6,11 +6,14 @@ view.product.customer.code.form product.customer.code -
- - - - + + + + + + + + @@ -20,10 +23,11 @@ product.customer.code + + - @@ -40,10 +44,11 @@ product.customer.code + + - diff --git a/product_customer_code/product_product_view.xml b/product_customer_code/views/product_product_view.xml similarity index 90% rename from product_customer_code/product_product_view.xml rename to product_customer_code/views/product_product_view.xml index 3aec998b591..d5585a50bc0 100644 --- a/product_customer_code/product_product_view.xml +++ b/product_customer_code/views/product_product_view.xml @@ -13,9 +13,6 @@ -
@@ -28,4 +25,4 @@ - \ No newline at end of file +