From 72cc7e75c2d908fe044c0c775f2fff740d908fb8 Mon Sep 17 00:00:00 2001 From: Cyril Gaudin Date: Thu, 21 Apr 2016 16:32:59 +0200 Subject: [PATCH] product_warranty: migration V9 --- product_warranty/README.rst | 1 + product_warranty/__init__.py | 23 +---- product_warranty/__openerp__.py | 4 +- product_warranty/demo/product_warranty.xml | 2 +- product_warranty/models/__init__.py | 23 +---- .../models/product_supplierinfo.py | 83 +++++++------------ product_warranty/models/res_company.py | 25 +----- product_warranty/models/return_instruction.py | 25 +----- .../tests/test_product_warranty.py | 50 +++++------ .../views/product_warranty_view.xml | 40 +++------ product_warranty/views/res_company_view.xml | 6 +- 11 files changed, 84 insertions(+), 198 deletions(-) diff --git a/product_warranty/README.rst b/product_warranty/README.rst index ebe7a63c..a7ad1661 100644 --- a/product_warranty/README.rst +++ b/product_warranty/README.rst @@ -32,6 +32,7 @@ Contributors * Joël Grand-Guillaume * Ondřej Kuzník * Yanina Aular +* Cyril Gaudin Maintainer ---------- diff --git a/product_warranty/__init__.py b/product_warranty/__init__.py index 7297bf89..0d135c28 100644 --- a/product_warranty/__init__.py +++ b/product_warranty/__init__.py @@ -1,23 +1,6 @@ # -*- coding: utf-8 -*- -######################################################################### -# # -# # -######################################################################### -# # -# Copyright (C) 2009-2011 Akretion, Emmanuel Samyn # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU 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 General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -######################################################################### +# © 2016 Cyril Gaudin (Camptocamp) +# © 2009-2011 Akretion, Emmanuel Samyn +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/product_warranty/__openerp__.py b/product_warranty/__openerp__.py index 79f4e8c1..64864487 100644 --- a/product_warranty/__openerp__.py +++ b/product_warranty/__openerp__.py @@ -22,7 +22,7 @@ { 'name': 'Product warranty', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'category': 'Generic Modules/Product', 'author': "Akretion,Odoo Community Association (OCA),Vauxoo", 'website': 'http://akretion.com', @@ -38,7 +38,7 @@ 'demo/res_company.xml', ], 'test': [], - 'installable': False, + 'installable': True, 'active': False, 'images': ['images/product_warranty.png'], } diff --git a/product_warranty/demo/product_warranty.xml b/product_warranty/demo/product_warranty.xml index 6f7f3f8e..faea7cc5 100644 --- a/product_warranty/demo/product_warranty.xml +++ b/product_warranty/demo/product_warranty.xml @@ -37,7 +37,7 @@ Select the product you want to return and the reason for the return. You will ne supplier 12 - + 5 1 diff --git a/product_warranty/models/__init__.py b/product_warranty/models/__init__.py index 8e2e2580..b29d709f 100644 --- a/product_warranty/models/__init__.py +++ b/product_warranty/models/__init__.py @@ -1,24 +1,7 @@ # -*- coding: utf-8 -*- -######################################################################### -# # -# # -######################################################################### -# # -# Copyright (C) 2009-2011 Akretion, Emmanuel Samyn # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU 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 General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -######################################################################### +# © 2016 Cyril Gaudin (Camptocamp) +# © 2009-2011 Akretion, Emmanuel Samyn +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import return_instruction from . import product_supplierinfo diff --git a/product_warranty/models/product_supplierinfo.py b/product_warranty/models/product_supplierinfo.py index 937eb284..c406f98c 100644 --- a/product_warranty/models/product_supplierinfo.py +++ b/product_warranty/models/product_supplierinfo.py @@ -1,25 +1,8 @@ # -*- coding: utf-8 -*- -# ######################################################################## -# # -# # -# ######################################################################## -# # -# Copyright 2015 Vauxoo -# Copyright (C) 2009-2011 Akretion, Emmanuel Samyn, Benoît Guillot # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU 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 General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -########################################################################## +# © 2016 Cyril Gaudin (Camptocamp) +# © 2015 Vauxoo +# © 2009-2011 Akretion, Emmanuel Samyn, Benoît Guillot +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import api, fields, models @@ -28,14 +11,6 @@ class ProductSupplierInfo(models.Model): _inherit = "product.supplierinfo" - @api.model - def get_warranty_return_partner(self): - result = [('company', 'Company'), - ('supplier', 'Supplier'), - ('other', 'Other'), - ] - return result - @api.model def _get_default_instructions(self): """ Get selected lines to add to exchange """ @@ -43,36 +18,35 @@ class ProductSupplierInfo(models.Model): .search([('is_default', '=', True)], limit=1) return instruction_ids - @api.one @api.depends('warranty_return_partner') def _compute_warranty_return_address(self): """ Method to return the partner delivery address or if none, the default address """ - return_partner = self.warranty_return_partner - partner_id = self.company_id.partner_id.id - if return_partner: - if return_partner == 'supplier': - partner_id = self.name.id - elif return_partner == 'company': - if self.company_id.crm_return_address_id: - partner_id = self.company_id.\ - crm_return_address_id.id - elif return_partner == 'other': - if self.warranty_return_other_address: - partner_id = self.\ - warranty_return_other_address.id - self.warranty_return_address = partner_id + for record in self: + return_partner = record.warranty_return_partner + partner_id = record.company_id.partner_id.id + if return_partner: + if return_partner == 'supplier': + partner_id = record.name.id + elif return_partner == 'company': + if record.company_id.crm_return_address_id: + partner_id = record.company_id.crm_return_address_id.id + elif return_partner == 'other': + if record.warranty_return_other_address: + partner_id = record.warranty_return_other_address.id + record.warranty_return_address = partner_id warranty_duration = fields.Float( 'Period', help="Warranty in month for this product/supplier relation. Only " "for company/supplier relation (purchase order) ; the " "customer/company relation (sale order) always use the " - "product main warranty field") + "product main warranty field" + ) warranty_return_partner = fields.Selection( - get_warranty_return_partner, - 'Return type', + [('company', 'Company'), ('supplier', 'Supplier'), ('other', 'Other')], + string='Return type', required=True, default='company', help="Who is in charge of the warranty return treatment toward the" @@ -81,22 +55,27 @@ class ProductSupplierInfo(models.Model): "brand manufacturer. Doesn't necessarly mean that the " "warranty to be applied is the one of the return partner " "(ie: can be returned to the company and be under the " - "brand warranty") + "brand warranty)" + ) return_instructions = fields.Many2one( 'return.instruction', 'Instructions', default=_get_default_instructions, - help="Instructions for product return") + help="Instructions for product return" + ) active_supplier = fields.Boolean( - help="Is this supplier still active, only for information") + help="Is this supplier still active, only for information" + ) warranty_return_address = fields.Many2one( 'res.partner', compute='_compute_warranty_return_address', string="Return address", help="Where the goods should be returned " - "(computed field based on other infos.)") + "(computed field based on other infos.)" + ) warranty_return_other_address = fields.Many2one( 'res.partner', string='Return address', help="Where the customer has to send back the product(s) " - "if warranty return is set to 'other'.") + "if warranty return is set to 'other'." + ) diff --git a/product_warranty/models/res_company.py b/product_warranty/models/res_company.py index fce2579e..8c7258cf 100644 --- a/product_warranty/models/res_company.py +++ b/product_warranty/models/res_company.py @@ -1,26 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright 2015 Vauxoo -# Copyright 2013 Camptocamp -# Copyright 2009-2013 Akretion, -# Author: Emmanuel Samyn, Raphaël Valyi, Sébastien Beau, -# Joel Grand-Guillaume -# -# 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 . -# -############################################################################## +# © 2016 Joel Grand-Guillaume, Cyril Gaudin (Camptocamp) +# © 2009-2013 Akretion, Emmanuel Samyn, Raphaël Valyi, Sébastien Beau +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import fields, models diff --git a/product_warranty/models/return_instruction.py b/product_warranty/models/return_instruction.py index 0c430d46..cb646a61 100644 --- a/product_warranty/models/return_instruction.py +++ b/product_warranty/models/return_instruction.py @@ -1,25 +1,8 @@ # -*- coding: utf-8 -*- -# ######################################################################## -# # -# # -# ######################################################################## -# # -# Copyright 2015 Vauxoo -# Copyright (C) 2009-2011 Akretion, Emmanuel Samyn, Benoît Guillot # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU 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 General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -########################################################################## +# © 2016 Cyril Gaudin (Camptocamp) +# © 2015 Vauxoo +# © 2009-2011 Akretion, Emmanuel Samyn, Benoît Guillot +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import fields, models diff --git a/product_warranty/tests/test_product_warranty.py b/product_warranty/tests/test_product_warranty.py index b6eb670c..98bb2ad8 100644 --- a/product_warranty/tests/test_product_warranty.py +++ b/product_warranty/tests/test_product_warranty.py @@ -1,23 +1,7 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Author: Yanina Aular -# Copyright 2015 Vauxoo -# -# 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 . -# -############################################################################## +# © 2016 Cyril Gaudin (Camptocamp) +# © 2015 Vauxoo, Yanina Aular +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp.tests.common import TransactionCase @@ -38,16 +22,19 @@ class TestProductWarranty(TransactionCase): product_tmpl_id = self.env.ref('product.product_product_3') partner_id = self.env.ref('base.res_partner_4') + other_partner = self.env.ref('base.res_partner_12') - supplierinfo_data = dict(name=partner_id.id, - product_name='Test SupplierInfo for' - ' display Default Instruction', - min_qty=4, - delay=5, - warranty_return_partner='supplier', - product_tmpl_id=product_tmpl_id.id,) - self.supplierinfo_brw = \ - self.supplierinfo.create(supplierinfo_data) + supplierinfo_data = dict( + name=partner_id.id, + product_name='Test SupplierInfo for display Default Instruction', + min_qty=4, + delay=5, + warranty_return_partner='supplier', + product_tmpl_id=product_tmpl_id.id, + warranty_return_other_address=other_partner.id, + ) + + self.supplierinfo_brw = self.supplierinfo.create(supplierinfo_data) def test_default_instruction(self): """ @@ -78,3 +65,10 @@ class TestProductWarranty(TransactionCase): self.assertEquals(self.supplierinfo_brw.warranty_return_address.id, self.supplierinfo_brw.company_id. crm_return_address_id.id) + + self.supplierinfo_brw.write({'warranty_return_partner': 'other'}) + + self.assertEquals( + self.supplierinfo_brw.warranty_return_address.id, + self.supplierinfo_brw.warranty_return_other_address.id + ) diff --git a/product_warranty/views/product_warranty_view.xml b/product_warranty/views/product_warranty_view.xml index 6148dc30..aef144f2 100644 --- a/product_warranty/views/product_warranty_view.xml +++ b/product_warranty/views/product_warranty_view.xml @@ -1,29 +1,7 @@ - - - - + product.return.instructions.tree return.instruction @@ -36,7 +14,7 @@ - + product.return.instructions.form return.instruction @@ -64,20 +42,20 @@ groups="base.group_no_one" id="menu_product_return_instructions_action" parent="product.prod_config_main" sequence="3"/> - + product.supplierinfo.warranty.tree product.supplierinfo - + - + @@ -87,7 +65,7 @@ product.supplierinfo - + @@ -97,12 +75,14 @@ - + - + diff --git a/product_warranty/views/res_company_view.xml b/product_warranty/views/res_company_view.xml index 973bd889..831c09d8 100644 --- a/product_warranty/views/res_company_view.xml +++ b/product_warranty/views/res_company_view.xml @@ -8,9 +8,11 @@ res.company - + - + + +