mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] repair_discount: black, isort, prettier
This commit is contained in:
@@ -7,11 +7,9 @@
|
|||||||
"version": "12.0.1.0.0",
|
"version": "12.0.1.0.0",
|
||||||
"category": "Manufacturing",
|
"category": "Manufacturing",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "Agile Business Group, "
|
"author": "Agile Business Group, " "Tecnativa, " "Odoo Community Association (OCA)",
|
||||||
"Tecnativa, "
|
"website": "https://github.com/OCA/manufacture",
|
||||||
"Odoo Community Association (OCA)",
|
"depends": ["repair"],
|
||||||
"website": "http://www.agilebg.com",
|
|
||||||
'depends': ['repair'],
|
|
||||||
"data": ["views/mrp_repair_view.xml"],
|
"data": ["views/mrp_repair_view.xml"],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,87 +3,77 @@
|
|||||||
# 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 odoo import api, fields, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
import odoo.addons.decimal_precision as dp
|
import odoo.addons.decimal_precision as dp
|
||||||
|
|
||||||
|
|
||||||
class RepairFee(models.Model):
|
class RepairFee(models.Model):
|
||||||
_inherit = 'repair.fee'
|
_inherit = "repair.fee"
|
||||||
|
|
||||||
@api.depends(
|
@api.depends("invoiced", "price_unit", "repair_id", "product_uom_qty", "product_id")
|
||||||
'invoiced',
|
|
||||||
'price_unit',
|
|
||||||
'repair_id',
|
|
||||||
'product_uom_qty',
|
|
||||||
'product_id')
|
|
||||||
def _compute_price_subtotal(self):
|
def _compute_price_subtotal(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
taxes = self.env['account.tax'].compute_all(
|
taxes = self.env["account.tax"].compute_all(
|
||||||
record.price_unit, record.repair_id.pricelist_id.currency_id,
|
record.price_unit,
|
||||||
record.product_uom_qty, record.product_id,
|
record.repair_id.pricelist_id.currency_id,
|
||||||
record.repair_id.partner_id
|
record.product_uom_qty,
|
||||||
|
record.product_id,
|
||||||
|
record.repair_id.partner_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
record.price_subtotal = (
|
record.price_subtotal = taxes["total_excluded"] * (
|
||||||
taxes['total_excluded'] * (1 - (record.discount or 0.0) / 100.0)
|
1 - (record.discount or 0.0) / 100.0
|
||||||
)
|
)
|
||||||
|
|
||||||
discount = fields.Float(string='Discount (%)')
|
discount = fields.Float(string="Discount (%)")
|
||||||
price_subtotal = fields.Float(
|
price_subtotal = fields.Float(
|
||||||
'Subtotal',
|
"Subtotal",
|
||||||
compute='_compute_price_subtotal',
|
compute="_compute_price_subtotal",
|
||||||
digits=dp.get_precision('Account'))
|
digits=dp.get_precision("Account"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RepairLine(models.Model):
|
class RepairLine(models.Model):
|
||||||
_inherit = 'repair.line'
|
_inherit = "repair.line"
|
||||||
|
|
||||||
@api.depends(
|
@api.depends("invoiced", "price_unit", "repair_id", "product_uom_qty", "product_id")
|
||||||
'invoiced',
|
|
||||||
'price_unit',
|
|
||||||
'repair_id',
|
|
||||||
'product_uom_qty',
|
|
||||||
'product_id')
|
|
||||||
def _compute_price_subtotal(self):
|
def _compute_price_subtotal(self):
|
||||||
for repair_line in 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.price_unit,
|
||||||
repair_line.repair_id.pricelist_id.currency_id,
|
repair_line.repair_id.pricelist_id.currency_id,
|
||||||
repair_line.product_uom_qty, repair_line.product_id,
|
repair_line.product_uom_qty,
|
||||||
repair_line.repair_id.partner_id
|
repair_line.product_id,
|
||||||
|
repair_line.repair_id.partner_id,
|
||||||
)
|
)
|
||||||
repair_line.price_subtotal = (
|
repair_line.price_subtotal = taxes["total_excluded"] * (
|
||||||
taxes['total_excluded'] * (1 - (repair_line.discount or 0.0) / 100.0)
|
1 - (repair_line.discount or 0.0) / 100.0
|
||||||
)
|
)
|
||||||
|
|
||||||
discount = fields.Float(string='Discount (%)')
|
discount = fields.Float(string="Discount (%)")
|
||||||
price_subtotal = fields.Float(
|
price_subtotal = fields.Float(
|
||||||
'Subtotal',
|
"Subtotal",
|
||||||
compute='_compute_price_subtotal',
|
compute="_compute_price_subtotal",
|
||||||
digits=dp.get_precision('Account'))
|
digits=dp.get_precision("Account"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RepairOrder(models.Model):
|
class RepairOrder(models.Model):
|
||||||
_inherit = 'repair.order'
|
_inherit = "repair.order"
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_invoice_create(self, group=False):
|
def action_invoice_create(self, group=False):
|
||||||
res = super(RepairOrder, self).action_invoice_create(group)
|
res = super(RepairOrder, self).action_invoice_create(group)
|
||||||
for repair in self.filtered(
|
for repair in self.filtered(lambda _repair: _repair.invoice_method != "none"):
|
||||||
lambda _repair: _repair.invoice_method != 'none'
|
|
||||||
):
|
|
||||||
operations = repair.operations
|
operations = repair.operations
|
||||||
fees_lines = repair.fees_lines
|
fees_lines = repair.fees_lines
|
||||||
|
|
||||||
for op in operations.filtered(
|
for op in operations.filtered(lambda item: item.invoice_line_id):
|
||||||
lambda item: item.invoice_line_id
|
|
||||||
):
|
|
||||||
op.invoice_line_id.discount = op.discount
|
op.invoice_line_id.discount = op.discount
|
||||||
if operations:
|
if operations:
|
||||||
repair.invoice_id.compute_taxes()
|
repair.invoice_id.compute_taxes()
|
||||||
|
|
||||||
for fee_lines in fees_lines.filtered(
|
for fee_lines in fees_lines.filtered(lambda item: item.invoice_line_id):
|
||||||
lambda item: item.invoice_line_id
|
|
||||||
):
|
|
||||||
fee_lines.invoice_line_id.discount = fee_lines.discount
|
fee_lines.invoice_line_id.discount = fee_lines.discount
|
||||||
if fees_lines:
|
if fees_lines:
|
||||||
repair.invoice_id.compute_taxes()
|
repair.invoice_id.compute_taxes()
|
||||||
@@ -93,8 +83,9 @@ class RepairOrder(models.Model):
|
|||||||
def _calculate_line_base_price(self, line):
|
def _calculate_line_base_price(self, line):
|
||||||
return line.price_unit * (1 - (line.discount or 0.0) / 100.0)
|
return line.price_unit * (1 - (line.discount or 0.0) / 100.0)
|
||||||
|
|
||||||
@api.depends('operations', 'fees_lines', 'operations.invoiced',
|
@api.depends(
|
||||||
'fees_lines.invoiced')
|
"operations", "fees_lines", "operations.invoiced", "fees_lines.invoiced"
|
||||||
|
)
|
||||||
def _amount_tax(self):
|
def _amount_tax(self):
|
||||||
for repair in self:
|
for repair in self:
|
||||||
taxed_amount = 0.0
|
taxed_amount = 0.0
|
||||||
@@ -106,11 +97,11 @@ class RepairOrder(models.Model):
|
|||||||
self.pricelist_id.currency_id,
|
self.pricelist_id.currency_id,
|
||||||
line.product_uom_qty,
|
line.product_uom_qty,
|
||||||
line.product_id,
|
line.product_id,
|
||||||
repair.partner_id
|
repair.partner_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
for c in tax_calculate['taxes']:
|
for c in tax_calculate["taxes"]:
|
||||||
taxed_amount += c['amount']
|
taxed_amount += c["amount"]
|
||||||
|
|
||||||
for line in repair.fees_lines:
|
for line in repair.fees_lines:
|
||||||
tax_calculate = line.tax_id.compute_all(
|
tax_calculate = line.tax_id.compute_all(
|
||||||
@@ -118,8 +109,9 @@ class RepairOrder(models.Model):
|
|||||||
self.pricelist_id.currency_id,
|
self.pricelist_id.currency_id,
|
||||||
line.product_uom_qty,
|
line.product_uom_qty,
|
||||||
line.product_id,
|
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"]
|
||||||
|
|
||||||
repair.amount_tax = currency.round(taxed_amount)
|
repair.amount_tax = currency.round(taxed_amount)
|
||||||
|
|||||||
@@ -8,69 +8,77 @@ class TestMrpRepairDiscount(common.SavepointCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super(TestMrpRepairDiscount, cls).setUpClass()
|
super(TestMrpRepairDiscount, cls).setUpClass()
|
||||||
cls.product = cls.env['product.product'].create({
|
cls.product = cls.env["product.product"].create(
|
||||||
'name': 'Test product',
|
{
|
||||||
'standard_price': 10,
|
"name": "Test product",
|
||||||
'list_price': 20,
|
"standard_price": 10,
|
||||||
})
|
"list_price": 20,
|
||||||
cls.product_service = cls.env['product.product'].create({
|
}
|
||||||
'name': 'Test product service',
|
)
|
||||||
'standard_price': 10,
|
cls.product_service = cls.env["product.product"].create(
|
||||||
'list_price': 20,
|
{
|
||||||
})
|
"name": "Test product service",
|
||||||
|
"standard_price": 10,
|
||||||
|
"list_price": 20,
|
||||||
|
}
|
||||||
|
)
|
||||||
# cls.partner = cls.env['res.partner'].create({
|
# cls.partner = cls.env['res.partner'].create({
|
||||||
# 'name': 'Test partner',
|
# 'name': 'Test partner',
|
||||||
# })
|
# })
|
||||||
cls.partner = cls.env.ref('base.res_partner_address_1')
|
cls.partner = cls.env.ref("base.res_partner_address_1")
|
||||||
cls.location = cls.env['stock.location'].create({
|
cls.location = cls.env["stock.location"].create(
|
||||||
'name': 'Test location',
|
{
|
||||||
})
|
"name": "Test location",
|
||||||
cls.repair = cls.env['repair.order'].create({
|
}
|
||||||
'product_id': cls.product.id,
|
)
|
||||||
'partner_id': cls.partner.id,
|
cls.repair = cls.env["repair.order"].create(
|
||||||
'partner_invoice_id': cls.partner.id,
|
{
|
||||||
'product_uom': cls.product.uom_id.id,
|
"product_id": cls.product.id,
|
||||||
'location_id': cls.location.id,
|
"partner_id": cls.partner.id,
|
||||||
'invoice_method': 'b4repair',
|
"partner_invoice_id": cls.partner.id,
|
||||||
})
|
"product_uom": cls.product.uom_id.id,
|
||||||
domain_location = [('usage', '=', 'production')]
|
"location_id": cls.location.id,
|
||||||
stock_location_id = cls.env['stock.location'].search(domain_location, limit=1)
|
"invoice_method": "b4repair",
|
||||||
cls.repair_line = cls.env['repair.line'].create({
|
}
|
||||||
'repair_id': cls.repair.id,
|
)
|
||||||
'type': 'add',
|
domain_location = [("usage", "=", "production")]
|
||||||
'product_id': cls.product.id,
|
stock_location_id = cls.env["stock.location"].search(domain_location, limit=1)
|
||||||
'product_uom': cls.product.uom_id.id,
|
cls.repair_line = cls.env["repair.line"].create(
|
||||||
'name': 'Test line',
|
{
|
||||||
'location_id': cls.repair.location_id.id,
|
"repair_id": cls.repair.id,
|
||||||
'location_dest_id': stock_location_id.id,
|
"type": "add",
|
||||||
'product_uom_qty': 1,
|
"product_id": cls.product.id,
|
||||||
'price_unit': 20,
|
"product_uom": cls.product.uom_id.id,
|
||||||
'discount': 50,
|
"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({
|
cls.repair_fee = cls.env["repair.fee"].create(
|
||||||
'repair_id': cls.repair.id,
|
{
|
||||||
'name': 'Test Service',
|
"repair_id": cls.repair.id,
|
||||||
'product_id': cls.product_service.id,
|
"name": "Test Service",
|
||||||
'product_uom_qty': 1,
|
"product_id": cls.product_service.id,
|
||||||
'product_uom': cls.product_service.uom_id.id,
|
"product_uom_qty": 1,
|
||||||
'price_unit': 20,
|
"product_uom": cls.product_service.uom_id.id,
|
||||||
'discount': 50,
|
"price_unit": 20,
|
||||||
})
|
"discount": 50,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def test_discount(self):
|
def test_discount(self):
|
||||||
self.assertAlmostEqual(
|
self.assertAlmostEqual(self.repair_line.price_subtotal, 10)
|
||||||
self.repair_line.price_subtotal, 10)
|
self.assertAlmostEqual(self.repair_fee.price_subtotal, 10)
|
||||||
self.assertAlmostEqual(
|
self.assertAlmostEqual(self.repair.amount_total, 20)
|
||||||
self.repair_fee.price_subtotal, 10)
|
|
||||||
self.assertAlmostEqual(
|
|
||||||
self.repair.amount_total, 20)
|
|
||||||
|
|
||||||
def test_invoice_create(self):
|
def test_invoice_create(self):
|
||||||
self.repair.state = '2binvoiced'
|
self.repair.state = "2binvoiced"
|
||||||
res = self.repair.action_invoice_create()
|
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]
|
invoice_line = invoice.invoice_line_ids[0]
|
||||||
self.assertEqual(invoice_line.discount, 50)
|
self.assertEqual(invoice_line.discount, 50)
|
||||||
self.assertAlmostEqual(
|
self.assertAlmostEqual(invoice_line.price_subtotal, 10)
|
||||||
invoice_line.price_subtotal, 10)
|
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="view_repair_order_discount_form" model="ir.ui.view">
|
<record id="view_repair_order_discount_form" model="ir.ui.view">
|
||||||
<field name="name">repair.discount.form</field>
|
<field name="name">repair.discount.form</field>
|
||||||
<field name="model">repair.order</field>
|
<field name="model">repair.order</field>
|
||||||
<field name="inherit_id" ref="repair.view_repair_order_form" />
|
<field name="inherit_id" ref="repair.view_repair_order_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='operations']/tree/field[@name='price_subtotal']" position='before'>
|
<xpath
|
||||||
<field name="discount"/>
|
expr="//field[@name='operations']/tree/field[@name='price_subtotal']"
|
||||||
|
position='before'
|
||||||
|
>
|
||||||
|
<field name="discount" />
|
||||||
</xpath>
|
</xpath>
|
||||||
<xpath expr="//field[@name='fees_lines']/tree/field[@name='price_unit']" position='after'>
|
<xpath
|
||||||
<field name="discount"/>
|
expr="//field[@name='fees_lines']/tree/field[@name='price_unit']"
|
||||||
|
position='after'
|
||||||
|
>
|
||||||
|
<field name="discount" />
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
1
setup/repair_discount/odoo/addons/repair_discount
Symbolic link
1
setup/repair_discount/odoo/addons/repair_discount
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../../repair_discount
|
||||||
6
setup/repair_discount/setup.py
Normal file
6
setup/repair_discount/setup.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user