mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
mrp_discount: New API + tests
This commit is contained in:
committed by
hurrinico
parent
9afc2668db
commit
7fb6bdaf58
@@ -38,6 +38,7 @@ Contributors
|
||||
------------
|
||||
|
||||
* Nicola Malcontenti <nicola.malcontenti@agilebg.com>
|
||||
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
@@ -52,4 +53,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2015 Nicola Malcontenti - Agile Business Group
|
||||
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
@@ -7,7 +8,9 @@
|
||||
"version": "8.0.1.0.0",
|
||||
"category": "Manufactoring",
|
||||
"license": "AGPL-3",
|
||||
"author": "Agile Business Group, Odoo Community Association (OCA)",
|
||||
"author": "Agile Business Group, "
|
||||
"Tecnativa, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"website": "http://www.agilebg.com",
|
||||
"contributors": [
|
||||
"Nicola Malcontenti <nicola.malcontenti@gmail.com>",
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2015 Nicola Malcontenti - Agile Business Group
|
||||
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import fields, models
|
||||
from openerp.osv import orm
|
||||
from openerp import api, fields, models
|
||||
from openerp.osv import fields as old_fields
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class MrpRepairLine(models.Model):
|
||||
@@ -11,14 +13,32 @@ class MrpRepairLine(models.Model):
|
||||
|
||||
discount = fields.Float(string='Discount (%)')
|
||||
|
||||
@api.multi
|
||||
def _amount_line(self, field_name, arg):
|
||||
res = super(MrpRepairLine, self)._amount_line(field_name, arg)
|
||||
for line in self.filtered('discount'):
|
||||
price = res[line.id] * (1 - (line.discount or 0.0) / 100.0)
|
||||
res[line.id] = price
|
||||
return res
|
||||
|
||||
class MrpRepair(orm.Model):
|
||||
_columns = {
|
||||
# Must be defined in old API so that we can call super in the compute
|
||||
'price_subtotal': old_fields.function(
|
||||
_amount_line, string='Subtotal',
|
||||
digits_compute=dp.get_precision('Account')),
|
||||
}
|
||||
|
||||
|
||||
class MrpRepair(models.Model):
|
||||
_inherit = 'mrp.repair'
|
||||
|
||||
def action_invoice_create(self, cr, uid, ids, group=False, context=None):
|
||||
res = super(MrpRepair, self).action_invoice_create(
|
||||
cr, uid, ids, group, context)
|
||||
repair_obj = self.browse(cr, uid, ids, context=context)
|
||||
for op in repair_obj.operations:
|
||||
op.invoice_line_id.discount = op.discount
|
||||
@api.multi
|
||||
def action_invoice_create(self, group=False):
|
||||
res = super(MrpRepair, self).action_invoice_create(group)
|
||||
for repair in self:
|
||||
operations = repair.operations.filtered('to_invoice')
|
||||
for op in operations:
|
||||
op.invoice_line_id.discount = op.discount
|
||||
if operations:
|
||||
repair.invoice_id.button_reset_taxes()
|
||||
return res
|
||||
|
||||
4
mrp_repair_discount/tests/__init__.py
Normal file
4
mrp_repair_discount/tests/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import test_mrp_repair_discount
|
||||
62
mrp_repair_discount/tests/test_mrp_repair_discount.py
Normal file
62
mrp_repair_discount/tests/test_mrp_repair_discount.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# © 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp.tests import common
|
||||
|
||||
|
||||
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.partner = cls.env['res.partner'].create({
|
||||
'name': 'Test partner',
|
||||
})
|
||||
cls.location = cls.env['stock.location'].create({
|
||||
'name': 'Test location',
|
||||
})
|
||||
cls.repair = cls.env['mrp.repair'].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,
|
||||
'location_dest_id': cls.location.id,
|
||||
'invoice_method': 'b4repair',
|
||||
})
|
||||
cls.repair_line = cls.env['mrp.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': cls.repair.location_dest_id.id,
|
||||
'product_uom_qty': 1,
|
||||
'price_unit': 20,
|
||||
'discount': 50,
|
||||
'to_invoice': True,
|
||||
})
|
||||
|
||||
def test_discount(self):
|
||||
self.assertAlmostEqual(
|
||||
self.repair_line.price_subtotal, 10,
|
||||
self.repair_line._columns['price_subtotal'].digits[1])
|
||||
self.assertAlmostEqual(
|
||||
self.repair.amount_total, 10,
|
||||
self.repair._columns['amount_total'].digits[1])
|
||||
|
||||
def test_invoice_create(self):
|
||||
self.repair.state = '2binvoiced'
|
||||
res = self.repair.action_invoice_create()
|
||||
invoice = self.env['account.invoice'].browse(res.values()[0])
|
||||
invoice_line = invoice.invoice_line[0]
|
||||
self.assertEqual(invoice_line.discount, 50)
|
||||
self.assertAlmostEqual(
|
||||
invoice_line.price_subtotal, 10,
|
||||
invoice_line._columns['price_subtotal'].digits[1])
|
||||
Reference in New Issue
Block a user