[IMP] repair_discount: black, isort, prettier

This commit is contained in:
manu
2022-05-12 11:03:36 +02:00
parent 22b27584fa
commit 837fabe7e7
6 changed files with 127 additions and 116 deletions

View File

@@ -7,11 +7,9 @@
"version": "12.0.1.0.0",
"category": "Manufacturing",
"license": "AGPL-3",
"author": "Agile Business Group, "
"Tecnativa, "
"Odoo Community Association (OCA)",
"website": "http://www.agilebg.com",
'depends': ['repair'],
"author": "Agile Business Group, " "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture",
"depends": ["repair"],
"data": ["views/mrp_repair_view.xml"],
"installable": True,
}

View File

@@ -3,87 +3,77 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
import odoo.addons.decimal_precision as dp
class RepairFee(models.Model):
_inherit = 'repair.fee'
_inherit = "repair.fee"
@api.depends(
'invoiced',
'price_unit',
'repair_id',
'product_uom_qty',
'product_id')
@api.depends("invoiced", "price_unit", "repair_id", "product_uom_qty", "product_id")
def _compute_price_subtotal(self):
for record in self:
taxes = self.env['account.tax'].compute_all(
record.price_unit, record.repair_id.pricelist_id.currency_id,
record.product_uom_qty, record.product_id,
record.repair_id.partner_id
taxes = self.env["account.tax"].compute_all(
record.price_unit,
record.repair_id.pricelist_id.currency_id,
record.product_uom_qty,
record.product_id,
record.repair_id.partner_id,
)
record.price_subtotal = (
taxes['total_excluded'] * (1 - (record.discount or 0.0) / 100.0)
record.price_subtotal = taxes["total_excluded"] * (
1 - (record.discount or 0.0) / 100.0
)
discount = fields.Float(string='Discount (%)')
discount = fields.Float(string="Discount (%)")
price_subtotal = fields.Float(
'Subtotal',
compute='_compute_price_subtotal',
digits=dp.get_precision('Account'))
"Subtotal",
compute="_compute_price_subtotal",
digits=dp.get_precision("Account"),
)
class RepairLine(models.Model):
_inherit = 'repair.line'
_inherit = "repair.line"
@api.depends(
'invoiced',
'price_unit',
'repair_id',
'product_uom_qty',
'product_id')
@api.depends("invoiced", "price_unit", "repair_id", "product_uom_qty", "product_id")
def _compute_price_subtotal(self):
for repair_line in self:
taxes = self.env['account.tax'].compute_all(
taxes = self.env["account.tax"].compute_all(
repair_line.price_unit,
repair_line.repair_id.pricelist_id.currency_id,
repair_line.product_uom_qty, repair_line.product_id,
repair_line.repair_id.partner_id
repair_line.product_uom_qty,
repair_line.product_id,
repair_line.repair_id.partner_id,
)
repair_line.price_subtotal = (
taxes['total_excluded'] * (1 - (repair_line.discount or 0.0) / 100.0)
repair_line.price_subtotal = taxes["total_excluded"] * (
1 - (repair_line.discount or 0.0) / 100.0
)
discount = fields.Float(string='Discount (%)')
discount = fields.Float(string="Discount (%)")
price_subtotal = fields.Float(
'Subtotal',
compute='_compute_price_subtotal',
digits=dp.get_precision('Account'))
"Subtotal",
compute="_compute_price_subtotal",
digits=dp.get_precision("Account"),
)
class RepairOrder(models.Model):
_inherit = 'repair.order'
_inherit = "repair.order"
@api.multi
def action_invoice_create(self, group=False):
res = super(RepairOrder, self).action_invoice_create(group)
for repair in self.filtered(
lambda _repair: _repair.invoice_method != 'none'
):
for repair in self.filtered(lambda _repair: _repair.invoice_method != "none"):
operations = repair.operations
fees_lines = repair.fees_lines
for op in operations.filtered(
lambda item: item.invoice_line_id
):
for op in operations.filtered(lambda item: item.invoice_line_id):
op.invoice_line_id.discount = op.discount
if operations:
repair.invoice_id.compute_taxes()
for fee_lines in fees_lines.filtered(
lambda item: item.invoice_line_id
):
for fee_lines in fees_lines.filtered(lambda item: item.invoice_line_id):
fee_lines.invoice_line_id.discount = fee_lines.discount
if fees_lines:
repair.invoice_id.compute_taxes()
@@ -93,8 +83,9 @@ class RepairOrder(models.Model):
def _calculate_line_base_price(self, line):
return line.price_unit * (1 - (line.discount or 0.0) / 100.0)
@api.depends('operations', 'fees_lines', 'operations.invoiced',
'fees_lines.invoiced')
@api.depends(
"operations", "fees_lines", "operations.invoiced", "fees_lines.invoiced"
)
def _amount_tax(self):
for repair in self:
taxed_amount = 0.0
@@ -106,11 +97,11 @@ class RepairOrder(models.Model):
self.pricelist_id.currency_id,
line.product_uom_qty,
line.product_id,
repair.partner_id
repair.partner_id,
)
for c in tax_calculate['taxes']:
taxed_amount += c['amount']
for c in tax_calculate["taxes"]:
taxed_amount += c["amount"]
for line in repair.fees_lines:
tax_calculate = line.tax_id.compute_all(
@@ -118,8 +109,9 @@ class RepairOrder(models.Model):
self.pricelist_id.currency_id,
line.product_uom_qty,
line.product_id,
repair.partner_id)
for c in tax_calculate['taxes']:
taxed_amount += c['amount']
repair.partner_id,
)
for c in tax_calculate["taxes"]:
taxed_amount += c["amount"]
repair.amount_tax = currency.round(taxed_amount)

View File

@@ -8,69 +8,77 @@ class TestMrpRepairDiscount(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestMrpRepairDiscount, cls).setUpClass()
cls.product = cls.env['product.product'].create({
'name': 'Test product',
'standard_price': 10,
'list_price': 20,
})
cls.product_service = cls.env['product.product'].create({
'name': 'Test product service',
'standard_price': 10,
'list_price': 20,
})
cls.product = cls.env["product.product"].create(
{
"name": "Test product",
"standard_price": 10,
"list_price": 20,
}
)
cls.product_service = cls.env["product.product"].create(
{
"name": "Test product service",
"standard_price": 10,
"list_price": 20,
}
)
# cls.partner = cls.env['res.partner'].create({
# 'name': 'Test partner',
# })
cls.partner = cls.env.ref('base.res_partner_address_1')
cls.location = cls.env['stock.location'].create({
'name': 'Test location',
})
cls.repair = cls.env['repair.order'].create({
'product_id': cls.product.id,
'partner_id': cls.partner.id,
'partner_invoice_id': cls.partner.id,
'product_uom': cls.product.uom_id.id,
'location_id': cls.location.id,
'invoice_method': 'b4repair',
})
domain_location = [('usage', '=', 'production')]
stock_location_id = cls.env['stock.location'].search(domain_location, limit=1)
cls.repair_line = cls.env['repair.line'].create({
'repair_id': cls.repair.id,
'type': 'add',
'product_id': cls.product.id,
'product_uom': cls.product.uom_id.id,
'name': 'Test line',
'location_id': cls.repair.location_id.id,
'location_dest_id': stock_location_id.id,
'product_uom_qty': 1,
'price_unit': 20,
'discount': 50,
})
cls.partner = cls.env.ref("base.res_partner_address_1")
cls.location = cls.env["stock.location"].create(
{
"name": "Test location",
}
)
cls.repair = cls.env["repair.order"].create(
{
"product_id": cls.product.id,
"partner_id": cls.partner.id,
"partner_invoice_id": cls.partner.id,
"product_uom": cls.product.uom_id.id,
"location_id": cls.location.id,
"invoice_method": "b4repair",
}
)
domain_location = [("usage", "=", "production")]
stock_location_id = cls.env["stock.location"].search(domain_location, limit=1)
cls.repair_line = cls.env["repair.line"].create(
{
"repair_id": cls.repair.id,
"type": "add",
"product_id": cls.product.id,
"product_uom": cls.product.uom_id.id,
"name": "Test line",
"location_id": cls.repair.location_id.id,
"location_dest_id": stock_location_id.id,
"product_uom_qty": 1,
"price_unit": 20,
"discount": 50,
}
)
cls.repair_fee = cls.env['repair.fee'].create({
'repair_id': cls.repair.id,
'name': 'Test Service',
'product_id': cls.product_service.id,
'product_uom_qty': 1,
'product_uom': cls.product_service.uom_id.id,
'price_unit': 20,
'discount': 50,
})
cls.repair_fee = cls.env["repair.fee"].create(
{
"repair_id": cls.repair.id,
"name": "Test Service",
"product_id": cls.product_service.id,
"product_uom_qty": 1,
"product_uom": cls.product_service.uom_id.id,
"price_unit": 20,
"discount": 50,
}
)
def test_discount(self):
self.assertAlmostEqual(
self.repair_line.price_subtotal, 10)
self.assertAlmostEqual(
self.repair_fee.price_subtotal, 10)
self.assertAlmostEqual(
self.repair.amount_total, 20)
self.assertAlmostEqual(self.repair_line.price_subtotal, 10)
self.assertAlmostEqual(self.repair_fee.price_subtotal, 10)
self.assertAlmostEqual(self.repair.amount_total, 20)
def test_invoice_create(self):
self.repair.state = '2binvoiced'
self.repair.state = "2binvoiced"
res = self.repair.action_invoice_create()
invoice = self.env['account.invoice'].browse(res.values())[0]
invoice = self.env["account.invoice"].browse(res.values())[0]
invoice_line = invoice.invoice_line_ids[0]
self.assertEqual(invoice_line.discount, 50)
self.assertAlmostEqual(
invoice_line.price_subtotal, 10)
self.assertAlmostEqual(invoice_line.price_subtotal, 10)

View File

@@ -1,15 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_repair_order_discount_form" model="ir.ui.view">
<field name="name">repair.discount.form</field>
<field name="model">repair.order</field>
<field name="inherit_id" ref="repair.view_repair_order_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='operations']/tree/field[@name='price_subtotal']" position='before'>
<field name="discount"/>
<xpath
expr="//field[@name='operations']/tree/field[@name='price_subtotal']"
position='before'
>
<field name="discount" />
</xpath>
<xpath expr="//field[@name='fees_lines']/tree/field[@name='price_unit']" position='after'>
<field name="discount"/>
<xpath
expr="//field[@name='fees_lines']/tree/field[@name='price_unit']"
position='after'
>
<field name="discount" />
</xpath>
</field>
</record>

View File

@@ -0,0 +1 @@
../../../../repair_discount

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)