[IMP] product_warranty: black, isort, prettier

This commit is contained in:
Ernesto Tejeda
2020-11-02 11:58:26 -05:00
committed by Lois Suarez
parent 0531191bee
commit 27f61c3993
12 changed files with 187 additions and 190 deletions

View File

@@ -2,29 +2,21 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'Product Warranty', "name": "Product Warranty",
'version': '12.0.1.0.0', "version": "12.0.1.0.0",
'category': 'Generic Modules/Product', "category": "Generic Modules/Product",
'author': 'Akretion, Vauxoo, Odoo Community Association (OCA)', "author": "Akretion, Vauxoo, Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/rma', "website": "https://github.com/OCA/rma",
'license': 'AGPL-3', "license": "AGPL-3",
'depends': [ "depends": ["sale_management",],
'sale_management', "data": [
"security/ir.model.access.csv",
"views/res_company.xml",
"views/product_warranty.xml",
"views/product_template.xml",
], ],
'data': [ "demo": ["demo/product_warranty.xml", "demo/res_company.xml",],
'security/ir.model.access.csv', "images": ["images/product_warranty.png"],
'views/res_company.xml', "development_status": "Production/Stable",
'views/product_warranty.xml', "maintainers": ["osi-scampbell", "max3903",],
'views/product_template.xml'
],
'demo': [
'demo/product_warranty.xml',
'demo/res_company.xml',
],
'images': ['images/product_warranty.png'],
'development_status': 'Production/Stable',
'maintainers': [
'osi-scampbell',
'max3903',
]
} }

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1"> <odoo noupdate="1">
<record id="return_instruction_1" model="return.instruction"> <record id="return_instruction_1" model="return.instruction">
<field name="name">Default Instruction</field> <field name="name">Default Instruction</field>
<field name="instructions">To return a product purchased through our <field name="instructions">To return a product purchased through our
@@ -14,7 +13,6 @@
</field> </field>
<field name="is_default">1</field> <field name="is_default">1</field>
</record> </record>
<record id="return_instruction_2" model="return.instruction"> <record id="return_instruction_2" model="return.instruction">
<field name="name">Provisional Instruction</field> <field name="name">Provisional Instruction</field>
<field name="instructions">Under the provisions of these Conditions of <field name="instructions">Under the provisions of these Conditions of
@@ -29,53 +27,47 @@
entitled to charge the products or the costs of recovery. entitled to charge the products or the costs of recovery.
</field> </field>
</record> </record>
<!-- Warranty Information of PC Assemble SC234 Product in Supplier Info --> <!-- Warranty Information of PC Assemble SC234 Product in Supplier Info -->
<record id="product.product_product_3_product_template" <record id="product.product_product_3_product_template" model="product.template">
model="product.template">
<field name="warranty">5</field> <field name="warranty">5</field>
</record> </record>
<record id="product_supplierinfo_warranty_31" model="product.supplierinfo"> <record id="product_supplierinfo_warranty_31" model="product.supplierinfo">
<field name="return_instructions" ref="return_instruction_2" /> <field name="return_instructions" ref="return_instruction_2" />
<field name="warranty_return_partner">other</field> <field name="warranty_return_partner">other</field>
<field name="warranty_return_other_address" <field name="warranty_return_other_address" ref="base.res_partner_address_7" />
ref="base.res_partner_address_7"/>
<field name="warranty_duration">8</field> <field name="warranty_duration">8</field>
<field name="product_tmpl_id" <field
ref="product.product_product_3_product_template"/> name="product_tmpl_id"
ref="product.product_product_3_product_template"
/>
<field name="name" ref="base.res_partner_4" /> <field name="name" ref="base.res_partner_4" />
<field name="delay">5</field> <field name="delay">5</field>
<field name="min_qty">1</field> <field name="min_qty">1</field>
</record> </record>
<record id="product_supplierinfo_warranty_32" model="product.supplierinfo"> <record id="product_supplierinfo_warranty_32" model="product.supplierinfo">
<field name="return_instructions" ref="return_instruction_1" /> <field name="return_instructions" ref="return_instruction_1" />
<field name="warranty_return_partner">supplier</field> <field name="warranty_return_partner">supplier</field>
<field name="warranty_duration">12</field> <field name="warranty_duration">12</field>
<field name="product_tmpl_id" <field
ref="product.product_product_3_product_template"/> name="product_tmpl_id"
ref="product.product_product_3_product_template"
/>
<field name="name" ref="base.res_partner_3" /> <field name="name" ref="base.res_partner_3" />
<field name="delay">5</field> <field name="delay">5</field>
<field name="min_qty">1</field> <field name="min_qty">1</field>
</record> </record>
<!-- Warranty Information of iMac Product in Supplier Info --> <!-- Warranty Information of iMac Product in Supplier Info -->
<record id="product.product_product_8_product_template" <record id="product.product_product_8_product_template" model="product.template">
model="product.template">
<field name="warranty">5</field> <field name="warranty">5</field>
</record> </record>
<record id="product.product_supplierinfo_5" model="product.supplierinfo"> <record id="product.product_supplierinfo_5" model="product.supplierinfo">
<field name="return_instructions" ref="return_instruction_1" /> <field name="return_instructions" ref="return_instruction_1" />
<field name="warranty_return_partner">supplier</field> <field name="warranty_return_partner">supplier</field>
<field name="warranty_duration">10</field> <field name="warranty_duration">10</field>
</record> </record>
<record id="product.product_supplierinfo_6" model="product.supplierinfo"> <record id="product.product_supplierinfo_6" model="product.supplierinfo">
<field name="return_instructions" ref="return_instruction_2" /> <field name="return_instructions" ref="return_instruction_2" />
<field name="warranty_return_partner">supplier</field> <field name="warranty_return_partner">supplier</field>
<field name="warranty_duration">6</field> <field name="warranty_duration">6</field>
</record> </record>
</odoo> </odoo>

View File

@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1"> <odoo noupdate="1">
<record id="base.main_company" model="res.company"> <record id="base.main_company" model="res.company">
<field name="crm_return_address_id" ref="base.res_partner_main1" /> <field name="crm_return_address_id" ref="base.res_partner_main1" />
</record> </record>
</odoo> </odoo>

View File

@@ -1,8 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import ( from . import return_instruction, product_supplierinfo, res_company, product_template
return_instruction,
product_supplierinfo,
res_company,
product_template
)

View File

@@ -12,10 +12,11 @@ class ProductSupplierInfo(models.Model):
@api.model @api.model
def _get_default_instructions(self): def _get_default_instructions(self):
""" Get selected lines to add to exchange """ """ Get selected lines to add to exchange """
return self.env['return.instruction']\ return self.env["return.instruction"].search(
.search([('is_default', '=', True)], limit=1) [("is_default", "=", True)], limit=1
)
@api.depends('warranty_return_partner') @api.depends("warranty_return_partner")
def _compute_warranty_return_address(self): def _compute_warranty_return_address(self):
""" Method to return the partner delivery address or if none, the """ Method to return the partner delivery address or if none, the
default address default address
@@ -23,47 +24,61 @@ class ProductSupplierInfo(models.Model):
for record in self: for record in self:
return_partner = record.warranty_return_partner return_partner = record.warranty_return_partner
partner_id = record.company_id.partner_id.id partner_id = record.company_id.partner_id.id
if return_partner and return_partner == 'supplier': if return_partner and return_partner == "supplier":
partner_id = record.name.id partner_id = record.name.id
elif return_partner and return_partner == 'company' and \ elif (
record.company_id.crm_return_address_id: return_partner
and return_partner == "company"
and record.company_id.crm_return_address_id
):
partner_id = record.company_id.crm_return_address_id.id partner_id = record.company_id.crm_return_address_id.id
elif return_partner and return_partner == 'other' and \ elif (
record.warranty_return_other_address: return_partner
and return_partner == "other"
and record.warranty_return_other_address
):
partner_id = record.warranty_return_other_address.id partner_id = record.warranty_return_other_address.id
record.warranty_return_address = partner_id record.warranty_return_address = partner_id
warranty_duration = fields.Float( warranty_duration = fields.Float(
'Period', "Period",
help="Warranty in month for this product/supplier relation. Only " help="Warranty in month for this product/supplier relation. Only "
"for company/supplier relation (purchase order) ; the " "for company/supplier relation (purchase order) ; the "
"customer/company relation (sale order) always use the " "customer/company relation (sale order) always use the "
"product main warranty field.") "product main warranty field.",
)
warranty_return_partner = fields.Selection( warranty_return_partner = fields.Selection(
[('company', 'Company'), ('supplier', 'Supplier'), ('other', 'Other')], [("company", "Company"), ("supplier", "Supplier"), ("other", "Other")],
string='Return type', required=True, default='company', string="Return type",
required=True,
default="company",
help="Who is in charge of the warranty return treatment toward the " help="Who is in charge of the warranty return treatment toward the "
"end customer. Company will use the current company " "end customer. Company will use the current company "
"delivery or default address and so on for supplier and " "delivery or default address and so on for supplier and "
"brand manufacturer. Doesn't necessarily mean that the " "brand manufacturer. Doesn't necessarily mean that the "
"warranty to be applied is the one of the return partner " "warranty to be applied is the one of the return partner "
"(ie: can be returned to the company and be under the " "(ie: can be returned to the company and be under the "
"brand warranty).") "brand warranty).",
)
return_instructions = fields.Many2one( return_instructions = fields.Many2one(
'return.instruction', "return.instruction",
'Instructions', "Instructions",
default=_get_default_instructions, default=_get_default_instructions,
help="Instructions for product return.") help="Instructions for product return.",
)
active_supplier = fields.Boolean( 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( warranty_return_address = fields.Many2one(
'res.partner', "res.partner",
compute='_compute_warranty_return_address', compute="_compute_warranty_return_address",
string="Return address", string="Return address",
help="Where the goods should be returned " 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( warranty_return_other_address = fields.Many2one(
'res.partner', "res.partner",
string='Return other address', string="Return other address",
help="Where the customer has to send back the product(s) " 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'.",
)

View File

@@ -7,10 +7,15 @@ from odoo import fields, models
class ProductTemplate(models.Model): class ProductTemplate(models.Model):
_inherit = "product.template" _inherit = "product.template"
warranty = fields.Integer(string='Warranty Duration') warranty = fields.Integer(string="Warranty Duration")
warranty_type = fields.Selection([('day', 'Day(s)'), warranty_type = fields.Selection(
('week', 'Week(s)'), [
('month', 'Month(s)'), ("day", "Day(s)"),
('year', 'Year(s)')], ("week", "Week(s)"),
string='Warranty Type', ("month", "Month(s)"),
required=True, default='day') ("year", "Year(s)"),
],
string="Warranty Type",
required=True,
default="day",
)

View File

@@ -9,8 +9,9 @@ class ResCompany(models.Model):
_inherit = "res.company" _inherit = "res.company"
crm_return_address_id = fields.Many2one( crm_return_address_id = fields.Many2one(
'res.partner', "res.partner",
string='Return address', string="Return address",
help="Default address where the customers has to send back the " help="Default address where the customers has to send back the "
"returned product. If empty, the address is the " "returned product. If empty, the address is the "
"company address.") "company address.",
)

View File

@@ -10,12 +10,12 @@ class ReturnInstruction(models.Model):
_name = "return.instruction" _name = "return.instruction"
_description = "Instructions for product return" _description = "Instructions for product return"
name = fields.Char('Title', required=True) name = fields.Char("Title", required=True)
instructions = fields.Text( instructions = fields.Text("Instructions", help="Instructions for product return.")
'Instructions', is_default = fields.Boolean(
help="Instructions for product return.") "Is default",
is_default = fields.Boolean('Is default',
help="If is default, will be use " help="If is default, will be use "
"to set the default value in " "to set the default value in "
"supplier info's. Be careful to " "supplier info's. Be careful to "
"have only one default.") "have only one default.",
)

View File

@@ -6,11 +6,10 @@ from odoo.tests.common import TransactionCase
class TestProductWarranty(TransactionCase): class TestProductWarranty(TransactionCase):
def setUp(self): def setUp(self):
super(TestProductWarranty, self).setUp() super(TestProductWarranty, self).setUp()
self.instruction_model = self.env['return.instruction'] self.instruction_model = self.env["return.instruction"]
self.supplierinfo = self.env['product.supplierinfo'] self.supplierinfo = self.env["product.supplierinfo"]
self.create_product_supplierinfo() self.create_product_supplierinfo()
def create_product_supplierinfo(self): def create_product_supplierinfo(self):
@@ -18,17 +17,17 @@ class TestProductWarranty(TransactionCase):
Create a record of product.supplier for next tests Create a record of product.supplier for next tests
""" """
product_tmpl_id = self.env.ref('product.product_product_3') product_tmpl_id = self.env.ref("product.product_product_3")
partner_id = self.env.ref('base.res_partner_4') partner_id = self.env.ref("base.res_partner_4")
other_partner = self.env.ref('base.res_partner_12') other_partner = self.env.ref("base.res_partner_12")
supplierinfo_data = dict( supplierinfo_data = dict(
name=partner_id.id, name=partner_id.id,
product_name='Test SupplierInfo for display Default Instruction', product_name="Test SupplierInfo for display Default Instruction",
min_qty=4, min_qty=4,
delay=5, delay=5,
warranty_return_partner='supplier', warranty_return_partner="supplier",
product_tmpl_id=product_tmpl_id.id, product_tmpl_id=product_tmpl_id.id,
warranty_return_other_address=other_partner.id, warranty_return_other_address=other_partner.id,
) )
@@ -43,11 +42,13 @@ class TestProductWarranty(TransactionCase):
product.supplierinfo is created product.supplierinfo is created
""" """
return_instructions_id = self.env.ref('product_warranty.' return_instructions_id = self.env.ref(
'return_instruction_1') "product_warranty." "return_instruction_1"
)
self.assertEquals(self.supplierinfo_brw.return_instructions.id, self.assertEquals(
return_instructions_id.id) self.supplierinfo_brw.return_instructions.id, return_instructions_id.id
)
def test_warranty_return_address(self): def test_warranty_return_address(self):
""" """
@@ -56,18 +57,21 @@ class TestProductWarranty(TransactionCase):
""" """
self.create_product_supplierinfo() self.create_product_supplierinfo()
self.assertEquals(self.supplierinfo_brw.warranty_return_address.id, self.assertEquals(
self.supplierinfo_brw.name.id) self.supplierinfo_brw.warranty_return_address.id,
self.supplierinfo_brw.name.id,
)
self.supplierinfo_brw.write({'warranty_return_partner': 'company'}) self.supplierinfo_brw.write({"warranty_return_partner": "company"})
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.assertEquals(
self.supplierinfo_brw.warranty_return_address.id, self.supplierinfo_brw.warranty_return_address.id,
self.supplierinfo_brw.warranty_return_other_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,
) )

View File

@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<record id="product_template_extend_warranty" model="ir.ui.view"> <record id="product_template_extend_warranty" model="ir.ui.view">
<field name="model">product.template</field> <field name="model">product.template</field>
<field name="inherit_id" <field name="inherit_id" ref="product.product_template_form_view" />
ref="product.product_template_form_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<page name="sales" position="inside"> <page name="sales" position="inside">
<group> <group>
@@ -20,5 +18,4 @@
</page> </page>
</field> </field>
</record> </record>
</odoo> </odoo>

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<!-- return instructions tree view --> <!-- return instructions tree view -->
<record id="product_return_instructions_tree_view" model="ir.ui.view"> <record id="product_return_instructions_tree_view" model="ir.ui.view">
<field name="name">product.return.instructions.tree</field> <field name="name">product.return.instructions.tree</field>
@@ -13,7 +12,6 @@
</tree> </tree>
</field> </field>
</record> </record>
<!-- return instructions form view --> <!-- return instructions form view -->
<record id="product_return_instructions_form_view" model="ir.ui.view"> <record id="product_return_instructions_form_view" model="ir.ui.view">
<field name="name">product.return.instructions.form</field> <field name="name">product.return.instructions.form</field>
@@ -31,21 +29,20 @@
</form> </form>
</field> </field>
</record> </record>
<record id="product_return_instructions_action" model="ir.actions.act_window">
<record id="product_return_instructions_action"
model="ir.actions.act_window">
<field name="name">Products Return Instructions</field> <field name="name">Products Return Instructions</field>
<field name="res_model">return.instruction</field> <field name="res_model">return.instruction</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
<field name="view_id" ref="product_return_instructions_tree_view" /> <field name="view_id" ref="product_return_instructions_tree_view" />
</record> </record>
<menuitem
<menuitem action="product_return_instructions_action" action="product_return_instructions_action"
groups="base.group_no_one" groups="base.group_no_one"
id="menu_product_return_instructions_action" id="menu_product_return_instructions_action"
parent="sale.prod_config_main" sequence="3"/> parent="sale.prod_config_main"
sequence="3"
/>
<!-- supplier info tree view --> <!-- supplier info tree view -->
<record id="product_supplierinfo_warranty_tree_view" model="ir.ui.view"> <record id="product_supplierinfo_warranty_tree_view" model="ir.ui.view">
<field name="name">product.supplierinfo.warranty.tree</field> <field name="name">product.supplierinfo.warranty.tree</field>
@@ -61,7 +58,6 @@
</field> </field>
</field> </field>
</record> </record>
<!-- supplier info form view --> <!-- supplier info form view -->
<record id="product_supplierinfo_warranty_form_view" model="ir.ui.view"> <record id="product_supplierinfo_warranty_form_view" model="ir.ui.view">
<field name="name">product.supplierinfo.warranty.form</field> <field name="name">product.supplierinfo.warranty.form</field>
@@ -69,23 +65,25 @@
<field name="inherit_id" ref="product.product_supplierinfo_form_view" /> <field name="inherit_id" ref="product.product_supplierinfo_form_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//group[last()]" position="after"> <xpath expr="//group[last()]" position="after">
<group name="waranty_group" string="Warranty informations" <group name="waranty_group" string="Warranty informations" col="4">
col="4">
<field name="active_supplier" /> <field name="active_supplier" />
<field name="warranty_duration" /> <field name="warranty_duration" />
<field name="return_instructions" /> <field name="return_instructions" />
</group> </group>
<group col="4"> <group col="4">
<field name="warranty_return_partner" /> <field name="warranty_return_partner" />
<field name="warranty_return_other_address" <field
name="warranty_return_other_address"
attrs="{'invisible':[('warranty_return_partner', '!=', 'other')], 'required':[('warranty_return_partner', '=', 'other')]}" attrs="{'invisible':[('warranty_return_partner', '!=', 'other')], 'required':[('warranty_return_partner', '=', 'other')]}"
class="oe_inline"/> class="oe_inline"
<field name="warranty_return_address" />
<field
name="warranty_return_address"
attrs="{'invisible':[('warranty_return_partner', '=', 'other')]}" attrs="{'invisible':[('warranty_return_partner', '=', 'other')]}"
class="oe_inline"/> class="oe_inline"
/>
</group> </group>
</xpath> </xpath>
</field> </field>
</record> </record>
</odoo> </odoo>

View File

@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<odoo> <odoo>
<!-- INHERITED VIEW FOR THE OBJECT : res_company --> <!-- INHERITED VIEW FOR THE OBJECT : res_company -->
<record id="company_form" model="ir.ui.view"> <record id="company_form" model="ir.ui.view">
<field name="name">crm_claim_rma.company_form</field> <field name="name">crm_claim_rma.company_form</field>
<field name="model">res.company</field> <field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form" /> <field name="inherit_id" ref="base.view_company_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='company_registry']/ancestor::group" <xpath
position="after"> expr="//field[@name='company_registry']/ancestor::group"
position="after"
>
<separator string="CRM Product Return Address" /> <separator string="CRM Product Return Address" />
<group col="2"> <group col="2">
<group> <group>
@@ -18,5 +19,4 @@
</xpath> </xpath>
</field> </field>
</record> </record>
</odoo> </odoo>