[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).
{
'name': 'Product Warranty',
'version': '12.0.1.0.0',
'category': 'Generic Modules/Product',
'author': 'Akretion, Vauxoo, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/rma',
'license': 'AGPL-3',
'depends': [
'sale_management',
"name": "Product Warranty",
"version": "12.0.1.0.0",
"category": "Generic Modules/Product",
"author": "Akretion, Vauxoo, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/rma",
"license": "AGPL-3",
"depends": ["sale_management",],
"data": [
"security/ir.model.access.csv",
"views/res_company.xml",
"views/product_warranty.xml",
"views/product_template.xml",
],
'data': [
'security/ir.model.access.csv',
'views/res_company.xml',
'views/product_warranty.xml',
'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',
]
"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">
<record id="return_instruction_1" model="return.instruction">
<field name="name">Default Instruction</field>
<field name="instructions">To return a product purchased through our
@@ -14,7 +13,6 @@
</field>
<field name="is_default">1</field>
</record>
<record id="return_instruction_2" model="return.instruction">
<field name="name">Provisional Instruction</field>
<field name="instructions">Under the provisions of these Conditions of
@@ -29,53 +27,47 @@
entitled to charge the products or the costs of recovery.
</field>
</record>
<!-- Warranty Information of PC Assemble SC234 Product in Supplier Info -->
<record id="product.product_product_3_product_template"
model="product.template">
<record id="product.product_product_3_product_template" model="product.template">
<field name="warranty">5</field>
</record>
<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_other_address"
ref="base.res_partner_address_7"/>
<field name="warranty_return_other_address" ref="base.res_partner_address_7" />
<field name="warranty_duration">8</field>
<field name="product_tmpl_id"
ref="product.product_product_3_product_template"/>
<field name="name" ref="base.res_partner_4"/>
<field
name="product_tmpl_id"
ref="product.product_product_3_product_template"
/>
<field name="name" ref="base.res_partner_4" />
<field name="delay">5</field>
<field name="min_qty">1</field>
</record>
<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_duration">12</field>
<field name="product_tmpl_id"
ref="product.product_product_3_product_template"/>
<field name="name" ref="base.res_partner_3"/>
<field
name="product_tmpl_id"
ref="product.product_product_3_product_template"
/>
<field name="name" ref="base.res_partner_3" />
<field name="delay">5</field>
<field name="min_qty">1</field>
</record>
<!-- Warranty Information of iMac Product in Supplier Info -->
<record id="product.product_product_8_product_template"
model="product.template">
<record id="product.product_product_8_product_template" model="product.template">
<field name="warranty">5</field>
</record>
<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_duration">10</field>
</record>
<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_duration">6</field>
</record>
</odoo>

View File

@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<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>
</odoo>

View File

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

View File

@@ -12,10 +12,11 @@ class ProductSupplierInfo(models.Model):
@api.model
def _get_default_instructions(self):
""" Get selected lines to add to exchange """
return self.env['return.instruction']\
.search([('is_default', '=', True)], limit=1)
return self.env["return.instruction"].search(
[("is_default", "=", True)], limit=1
)
@api.depends('warranty_return_partner')
@api.depends("warranty_return_partner")
def _compute_warranty_return_address(self):
""" Method to return the partner delivery address or if none, the
default address
@@ -23,47 +24,61 @@ class ProductSupplierInfo(models.Model):
for record in self:
return_partner = record.warranty_return_partner
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
elif return_partner and return_partner == 'company' and \
record.company_id.crm_return_address_id:
elif (
return_partner
and return_partner == "company"
and record.company_id.crm_return_address_id
):
partner_id = record.company_id.crm_return_address_id.id
elif return_partner and return_partner == 'other' and \
record.warranty_return_other_address:
elif (
return_partner
and return_partner == "other"
and record.warranty_return_other_address
):
partner_id = record.warranty_return_other_address.id
record.warranty_return_address = partner_id
warranty_duration = fields.Float(
'Period',
"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(
[('company', 'Company'), ('supplier', 'Supplier'), ('other', 'Other')],
string='Return type', required=True, default='company',
[("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 "
"end customer. Company will use the current company "
"delivery or default address and so on for supplier and "
"brand manufacturer. Doesn't necessarily 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',
"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',
"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 other address',
"res.partner",
string="Return other 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'.",
)

View File

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

View File

@@ -9,8 +9,9 @@ class ResCompany(models.Model):
_inherit = "res.company"
crm_return_address_id = fields.Many2one(
'res.partner',
string='Return address',
"res.partner",
string="Return address",
help="Default address where the customers has to send back 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"
_description = "Instructions for product return"
name = fields.Char('Title', required=True)
instructions = fields.Text(
'Instructions',
help="Instructions for product return.")
is_default = fields.Boolean('Is default',
name = fields.Char("Title", required=True)
instructions = fields.Text("Instructions", help="Instructions for product return.")
is_default = fields.Boolean(
"Is default",
help="If is default, will be use "
"to set the default value in "
"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):
def setUp(self):
super(TestProductWarranty, self).setUp()
self.instruction_model = self.env['return.instruction']
self.supplierinfo = self.env['product.supplierinfo']
self.instruction_model = self.env["return.instruction"]
self.supplierinfo = self.env["product.supplierinfo"]
self.create_product_supplierinfo()
def create_product_supplierinfo(self):
@@ -18,17 +17,17 @@ class TestProductWarranty(TransactionCase):
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')
other_partner = self.env.ref('base.res_partner_12')
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',
product_name="Test SupplierInfo for display Default Instruction",
min_qty=4,
delay=5,
warranty_return_partner='supplier',
warranty_return_partner="supplier",
product_tmpl_id=product_tmpl_id.id,
warranty_return_other_address=other_partner.id,
)
@@ -43,11 +42,13 @@ class TestProductWarranty(TransactionCase):
product.supplierinfo is created
"""
return_instructions_id = self.env.ref('product_warranty.'
'return_instruction_1')
return_instructions_id = self.env.ref(
"product_warranty." "return_instruction_1"
)
self.assertEquals(self.supplierinfo_brw.return_instructions.id,
return_instructions_id.id)
self.assertEquals(
self.supplierinfo_brw.return_instructions.id, return_instructions_id.id
)
def test_warranty_return_address(self):
"""
@@ -56,18 +57,21 @@ class TestProductWarranty(TransactionCase):
"""
self.create_product_supplierinfo()
self.assertEquals(self.supplierinfo_brw.warranty_return_address.id,
self.supplierinfo_brw.name.id)
self.assertEquals(
self.supplierinfo_brw.warranty_return_address.id,
self.supplierinfo_brw.name.id,
)
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.supplierinfo_brw.write({"warranty_return_partner": "company"})
self.assertEquals(
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,24 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="product_template_extend_warranty" model="ir.ui.view">
<field name="model">product.template</field>
<field name="inherit_id"
ref="product.product_template_form_view"/>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<page name="sales" position="inside">
<group>
<group string="Warranty" id="warranty-left">
<label name="warranty" for="warranty"/>
<label name="warranty" for="warranty" />
<div>
<field name="warranty" class="oe_inline"/>
<field name="warranty_type" class="oe_inline"/>
<field name="warranty" class="oe_inline" />
<field name="warranty_type" class="oe_inline" />
</div>
</group>
<group id="warranty-right"/>
<group id="warranty-right" />
</group>
</page>
</field>
</record>
</odoo>

View File

@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- return instructions tree view -->
<record id="product_return_instructions_tree_view" model="ir.ui.view">
<field name="name">product.return.instructions.tree</field>
<field name="model">return.instruction</field>
<field name="arch" type="xml">
<tree string="Return instructions">
<field name="name"/>
<field name="instructions"/>
<field name="is_default"/>
<field name="name" />
<field name="instructions" />
<field name="is_default" />
</tree>
</field>
</record>
<!-- return instructions form view -->
<record id="product_return_instructions_form_view" model="ir.ui.view">
<field name="name">product.return.instructions.form</field>
@@ -22,70 +20,70 @@
<form string="Return instructions">
<sheet>
<group name="return_instructions" col='4'>
<field name="name"/>
<field name="is_default"/>
<field name="name" />
<field name="is_default" />
</group>
<separator string="Instructions" colspan="4"/>
<field name="instructions" nolabel="1" colspan="4"/>
<separator string="Instructions" colspan="4" />
<field name="instructions" nolabel="1" colspan="4" />
</sheet>
</form>
</field>
</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="res_model">return.instruction</field>
<field name="view_type">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>
<menuitem action="product_return_instructions_action"
<menuitem
action="product_return_instructions_action"
groups="base.group_no_one"
id="menu_product_return_instructions_action"
parent="sale.prod_config_main" sequence="3"/>
parent="sale.prod_config_main"
sequence="3"
/>
<!-- supplier info tree view -->
<record id="product_supplierinfo_warranty_tree_view" model="ir.ui.view">
<field name="name">product.supplierinfo.warranty.tree</field>
<field name="model">product.supplierinfo</field>
<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
<field name="inherit_id" ref="product.product_supplierinfo_tree_view" />
<field name="arch" type="xml">
<field name="min_qty" position="before">
<field name="warranty_duration"/>
<field name="warranty_return_partner"/>
<field name="warranty_return_address"/>
<field name="active_supplier"/>
<field name="return_instructions"/>
<field name="warranty_duration" />
<field name="warranty_return_partner" />
<field name="warranty_return_address" />
<field name="active_supplier" />
<field name="return_instructions" />
</field>
</field>
</record>
<!-- supplier info form view -->
<record id="product_supplierinfo_warranty_form_view" model="ir.ui.view">
<field name="name">product.supplierinfo.warranty.form</field>
<field name="model">product.supplierinfo</field>
<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">
<xpath expr="//group[last()]" position="after">
<group name="waranty_group" string="Warranty informations"
col="4">
<field name="active_supplier"/>
<field name="warranty_duration"/>
<field name="return_instructions"/>
<group name="waranty_group" string="Warranty informations" col="4">
<field name="active_supplier" />
<field name="warranty_duration" />
<field name="return_instructions" />
</group>
<group col="4">
<field name="warranty_return_partner"/>
<field name="warranty_return_other_address"
<field name="warranty_return_partner" />
<field
name="warranty_return_other_address"
attrs="{'invisible':[('warranty_return_partner', '!=', 'other')], 'required':[('warranty_return_partner', '=', 'other')]}"
class="oe_inline"/>
<field name="warranty_return_address"
class="oe_inline"
/>
<field
name="warranty_return_address"
attrs="{'invisible':[('warranty_return_partner', '=', 'other')]}"
class="oe_inline"/>
class="oe_inline"
/>
</group>
</xpath>
</field>
</record>
</odoo>

View File

@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<!-- INHERITED VIEW FOR THE OBJECT : res_company -->
<record id="company_form" model="ir.ui.view">
<field name="name">crm_claim_rma.company_form</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">
<xpath expr="//field[@name='company_registry']/ancestor::group"
position="after">
<separator string="CRM Product Return Address"/>
<xpath
expr="//field[@name='company_registry']/ancestor::group"
position="after"
>
<separator string="CRM Product Return Address" />
<group col="2">
<group>
<field name="crm_return_address_id"/>
<field name="crm_return_address_id" />
</group>
</group>
</xpath>
</field>
</record>
</odoo>