From 48c67b1bca9ab485610949bf613a9bf30cc6baef Mon Sep 17 00:00:00 2001 From: Osval Reyes Date: Thu, 19 Nov 2015 15:05:16 -0430 Subject: [PATCH] [ADD] new module crm_rma_advance_warranty --- crm_rma_advance_warranty/README.rst | 71 +++++++++++ crm_rma_advance_warranty/__init__.py | 22 ++++ crm_rma_advance_warranty/__openerp__.py | 34 +++++ .../i18n/crm_rma_advance_warranty.pot | 40 ++++++ crm_rma_advance_warranty/i18n/es.po | 40 ++++++ crm_rma_advance_warranty/i18n/es_MX.po | 16 +++ crm_rma_advance_warranty/i18n/es_PA.po | 16 +++ crm_rma_advance_warranty/i18n/es_VE.po | 16 +++ crm_rma_advance_warranty/models/__init__.py | 22 ++++ crm_rma_advance_warranty/models/claim_line.py | 119 ++++++++++++++++++ crm_rma_advance_warranty/tests/__init__.py | 22 ++++ .../tests/test_crm_rma_advance_warranty.py | 105 ++++++++++++++++ 12 files changed, 523 insertions(+) create mode 100755 crm_rma_advance_warranty/README.rst create mode 100644 crm_rma_advance_warranty/__init__.py create mode 100644 crm_rma_advance_warranty/__openerp__.py create mode 100644 crm_rma_advance_warranty/i18n/crm_rma_advance_warranty.pot create mode 100644 crm_rma_advance_warranty/i18n/es.po create mode 100644 crm_rma_advance_warranty/i18n/es_MX.po create mode 100644 crm_rma_advance_warranty/i18n/es_PA.po create mode 100644 crm_rma_advance_warranty/i18n/es_VE.po create mode 100644 crm_rma_advance_warranty/models/__init__.py create mode 100644 crm_rma_advance_warranty/models/claim_line.py create mode 100755 crm_rma_advance_warranty/tests/__init__.py create mode 100644 crm_rma_advance_warranty/tests/test_crm_rma_advance_warranty.py diff --git a/crm_rma_advance_warranty/README.rst b/crm_rma_advance_warranty/README.rst new file mode 100755 index 00000000..3d4c0ccb --- /dev/null +++ b/crm_rma_advance_warranty/README.rst @@ -0,0 +1,71 @@ +.. 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 + +======================== +CRM RMA Advance Warranty +======================== + +This module makes improvements for warranty return address and warranty limit calculations method from **CRM Claim RMA** module using stored supplier information + +Installation +============ + +To install this module, you need to select it from available modules + +Configuration +============= + +No configuration is needed by this module + +Usage +===== + +This module will compute return address and warranty limit automatically when +adding/editing claim lines + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/145/8.0 + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +No issues are known yet + +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 +`here `_. + + +Credits +======= + +Contributors +------------ + +* Yanina Aular +* Osval Reyes + +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 http://odoo-community.org. diff --git a/crm_rma_advance_warranty/__init__.py b/crm_rma_advance_warranty/__init__.py new file mode 100644 index 00000000..001e1f21 --- /dev/null +++ b/crm_rma_advance_warranty/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright 2015 Vauxoo +# Author: Osval Reyes, Yanina Aular +# +# 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 . import models diff --git a/crm_rma_advance_warranty/__openerp__.py b/crm_rma_advance_warranty/__openerp__.py new file mode 100644 index 00000000..69024ed5 --- /dev/null +++ b/crm_rma_advance_warranty/__openerp__.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright 2015 Vauxoo +# Author: Osval Reyes, Yanina Aular +# +# 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': 'CRM RMA Advance Warranty', + 'version': '8.0.1.0.0', + 'author': 'Vauxoo,Odoo Community Association (OCA)', + 'website': 'http://www.vauxoo.com/', + 'license': 'AGPL-3', + 'category': 'Generic Modules/CRM & SRM', + 'depends': [ + 'crm_claim_rma', + 'crm_claim_product_supplier', + ], + 'installable': True, +} diff --git a/crm_rma_advance_warranty/i18n/crm_rma_advance_warranty.pot b/crm_rma_advance_warranty/i18n/crm_rma_advance_warranty.pot new file mode 100644 index 00000000..64d2e5b6 --- /dev/null +++ b/crm_rma_advance_warranty/i18n/crm_rma_advance_warranty.pot @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_rma_advance_warranty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-21 03:06+0000\n" +"PO-Revision-Date: 2015-07-21 03:06+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: crm_rma_advance_warranty +#: code:addons/crm_rma_advance_warranty/models/claim_line.py:41 +#, python-format +msgid "Cannot find any date for invoice. Must be a validated invoice." +msgstr "" + +#. module: crm_rma_advance_warranty +#: code:addons/crm_rma_advance_warranty/models/claim_line.py:40 +#: code:addons/crm_rma_advance_warranty/models/claim_line.py:57 +#, python-format +msgid "Error" +msgstr "" + +#. module: crm_rma_advance_warranty +#: model:ir.model,name:crm_rma_advance_warranty.model_claim_line +msgid "List of product to return" +msgstr "" + +#. module: crm_rma_advance_warranty +#: code:addons/crm_rma_advance_warranty/models/claim_line.py:58 +#, python-format +msgid "The product has no supplier configured for %s." +msgstr "" diff --git a/crm_rma_advance_warranty/i18n/es.po b/crm_rma_advance_warranty/i18n/es.po new file mode 100644 index 00000000..9a52ddbf --- /dev/null +++ b/crm_rma_advance_warranty/i18n/es.po @@ -0,0 +1,40 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_rma_advance_warranty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-21 03:06+0000\n" +"PO-Revision-Date: 2015-07-21 03:06+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: crm_rma_advance_warranty +#: code:addons/crm_rma_advance_warranty/model/crm_claim_rma.py:41 +#, python-format +msgid "Cannot find any date for invoice. Must be a validated invoice." +msgstr "No se puede encontrar ninguna fecha para la factura. Debe ser una factura validada." + +#. module: crm_rma_advance_warranty +#: code:addons/crm_rma_advance_warranty/model/crm_claim_rma.py:40 +#: code:addons/crm_rma_advance_warranty/model/crm_claim_rma.py:57 +#, python-format +msgid "Error" +msgstr "Error" + +#. module: crm_rma_advance_warranty +#: model:ir.model,name:crm_rma_advance_warranty.model_claim_line +msgid "List of product to return" +msgstr "Lista de productos a retornar" + +#. module: crm_rma_advance_warranty +#: code:addons/crm_rma_advance_warranty/model/crm_claim_rma.py:58 +#, python-format +msgid "The product has no supplier configured for %s." +msgstr "El producto no tiene un proveedor configurado para %s" diff --git a/crm_rma_advance_warranty/i18n/es_MX.po b/crm_rma_advance_warranty/i18n/es_MX.po new file mode 100644 index 00000000..bb1042c8 --- /dev/null +++ b/crm_rma_advance_warranty/i18n/es_MX.po @@ -0,0 +1,16 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_rma_advance_warranty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-17 19:38+0000\n" +"PO-Revision-Date: 2015-07-17 19:38+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" diff --git a/crm_rma_advance_warranty/i18n/es_PA.po b/crm_rma_advance_warranty/i18n/es_PA.po new file mode 100644 index 00000000..bb1042c8 --- /dev/null +++ b/crm_rma_advance_warranty/i18n/es_PA.po @@ -0,0 +1,16 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_rma_advance_warranty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-17 19:38+0000\n" +"PO-Revision-Date: 2015-07-17 19:38+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" diff --git a/crm_rma_advance_warranty/i18n/es_VE.po b/crm_rma_advance_warranty/i18n/es_VE.po new file mode 100644 index 00000000..bb1042c8 --- /dev/null +++ b/crm_rma_advance_warranty/i18n/es_VE.po @@ -0,0 +1,16 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_rma_advance_warranty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-17 19:38+0000\n" +"PO-Revision-Date: 2015-07-17 19:38+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" diff --git a/crm_rma_advance_warranty/models/__init__.py b/crm_rma_advance_warranty/models/__init__.py new file mode 100644 index 00000000..4ab5333c --- /dev/null +++ b/crm_rma_advance_warranty/models/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright 2015 Vauxoo +# Author: Osval Reyes, Yanina Aular +# +# 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 . import claim_line diff --git a/crm_rma_advance_warranty/models/claim_line.py b/crm_rma_advance_warranty/models/claim_line.py new file mode 100644 index 00000000..f0ea6115 --- /dev/null +++ b/crm_rma_advance_warranty/models/claim_line.py @@ -0,0 +1,119 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright 2015 Vauxoo +# Author: Osval Reyes, Yanina Aular +# +# 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 import _, api, exceptions, models +from datetime import datetime +from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, + DEFAULT_SERVER_DATETIME_FORMAT) + + +class ClaimLine(models.Model): + + _inherit = 'claim.line' + + @api.model + def set_warranty_limit(self): + """ + Calculate warranty limit + """ + if not self.invoice_date: + raise exceptions.Warning( + _('Error'), + _('Cannot find any date for invoice. ' + 'Must be a validated invoice.')) + warning = 'not_define' + date_inv_at_server = datetime.strptime(self.invoice_date, + DEFAULT_SERVER_DATETIME_FORMAT) + if self.warranty_type == 'supplier': + if self.prodlot_id: + supplier = self.prodlot_id.supplier_id + if supplier not in self.product_id.mapped('seller_ids.name'): + raise exceptions.Warning( + _('Error'), + _('The product has no supplier' + ' configured for %s.' % supplier.name)) + + psi_obj = self.env['product.supplierinfo'] + domain = [('name', '=', supplier.id), + ('product_tmpl_id', '=', + self.product_id.product_tmpl_id.id)] + seller = psi_obj.search(domain) + + warranty_duration = seller.warranty_duration + else: + warranty_duration = self.product_id.warranty + limit = self.warranty_limit(date_inv_at_server, warranty_duration) + # If waranty period was defined + if warranty_duration > 0: + claim_date = datetime.strptime(self.claim_id.date, + DEFAULT_SERVER_DATETIME_FORMAT) + if limit < claim_date: + warning = 'expired' + else: + warning = 'valid' + + self.write({ + 'guarantee_limit': limit.strftime(DEFAULT_SERVER_DATE_FORMAT), + 'warning': warning + }) + + @api.model + def set_warranty_return_address(self): + """ + Set the partner to be used as return destination and + the destination stock location of the line in case of Return. + + We can have various case here: + - company or other: return to company partner or + crm_return_address_id if specified + - supplier: return to the supplier address + + """ + return_address = None + psi_obj = self.env['product.supplierinfo'] + supplier = self.prodlot_id.supplier_id if self.prodlot_id else False + + if supplier and supplier in self.product_id.mapped('seller_ids.name'): + domain = [('name', '=', supplier.id), + ('product_tmpl_id', '=', + self.product_id.product_tmpl_id.id)] + supplier = psi_obj.search(domain) + return_address_id = \ + supplier.warranty_return_address.id + return_type = \ + supplier.warranty_return_partner + else: + # when no supplier is configured, returns to the company + company = self.claim_id.company_id + return_address = (company.crm_return_address_id or + company.partner_id) + return_address_id = return_address.id + return_type = 'company' + + location_dest_id = self.get_destination_location( + self.product_id, + self.claim_id.warehouse_id).id + + self.write({ + 'warranty_return_partner': return_address_id, + 'warranty_type': return_type, + 'location_dest_id': location_dest_id + }) diff --git a/crm_rma_advance_warranty/tests/__init__.py b/crm_rma_advance_warranty/tests/__init__.py new file mode 100755 index 00000000..df21cbaa --- /dev/null +++ b/crm_rma_advance_warranty/tests/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright 2015 Vauxoo +# Author: Osval Reyes +# +# 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 . import test_crm_rma_advance_warranty diff --git a/crm_rma_advance_warranty/tests/test_crm_rma_advance_warranty.py b/crm_rma_advance_warranty/tests/test_crm_rma_advance_warranty.py new file mode 100644 index 00000000..c906dfa8 --- /dev/null +++ b/crm_rma_advance_warranty/tests/test_crm_rma_advance_warranty.py @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright 2015 Vauxoo +# Author: Osval Reyes, +# Yanina Aular +# +# 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 versionself. +# +# 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.tests.common import TransactionCase + + +class TestCrmRmaAdvanceWarranty(TransactionCase): + + def setUp(self): + super(TestCrmRmaAdvanceWarranty, self).setUp() + self.claim = self.env['crm.claim'] + self.claim_line = self.env['claim.line'] + res_partner = self.env['res.partner'] + self.sale_order = self.env['sale.order'] + + self.claim_type = self.ref('crm_claim_type.crm_claim_type_customer') + self.supplier_id = res_partner.browse(self.ref('base.res_partner_1')) + + def get_customer_sale_order_and_invoice(self, set_supplier=False): + sale_order_id = self.sale_order.browse( + self.ref('sale.sale_order_7'))[0].copy() + # remove first order line just to simplify things up + sale_order_id.write({ + 'order_line': [(3, sale_order_id.order_line[0].id)] + }) + + if set_supplier: + sale_order_id.write({ + 'order_line': [(1, sale_order_id.order_line[0].id, { + 'supplier_id': self.supplier_id.id + }), (1, sale_order_id.order_line[1].id, { + 'supplier_id': self.supplier_id.id + }), (1, sale_order_id.order_line[2].id, { + 'supplier_id': self.supplier_id.id + }), ] + }) + + sale_order_id.action_button_confirm() + sale_order_id.action_invoice_create() + self.assertTrue(sale_order_id.invoice_ids) + + invoice_id = sale_order_id.invoice_ids[0] + invoice_id.signal_workflow('invoice_open') + return invoice_id + + def create_customer_claim(self, invoice_id): + """ + Create a customer claim with or without claim lines based + on include_lines parameter + """ + customer_id = invoice_id.partner_id + claim_id = self.claim.create({ + 'name': 'Test Claim for %s' % (customer_id.name), + 'claim_type': self.claim_type, + 'partner_id': customer_id.id, + 'pick': True, + 'code': '/', + 'invoice_id': invoice_id.id, + }) + claim_id.with_context( + {'create_lines': True})._onchange_invoice_warehouse_type_date() + return claim_id + + def test_01_warranty_company_limit(self): + invoice_id = self.get_customer_sale_order_and_invoice() + claim_id = self.create_customer_claim(invoice_id) + + # check if it has the same line count + self.assertEquals(len(invoice_id.invoice_line), + len(claim_id.claim_line_ids)) + + claim_id.claim_line_ids.set_warranty() + + # check if warranty set is company for all of them + wtypes = claim_id.mapped('claim_line_ids.warranty_type') + + self.assertFalse([w for w in wtypes if w != 'company']) + + for line_id in claim_id.claim_line_ids: + # warranty return address values + + self.assertTrue(line_id.warranty_return_partner + and line_id.warranty_type + and line_id.location_dest_id) + # warranty limit values + self.assertTrue(line_id.guarantee_limit + and line_id.set_warranty_limit)