FIX discount with taxes

ADD tests

FIX flake8

[FIX] Fix old_fields
This commit is contained in:
eLBati
2016-08-10 15:13:19 +02:00
committed by Lois Rilo
parent 73b4e4de8b
commit ebb8843058
4 changed files with 112 additions and 9 deletions

View File

@@ -7,7 +7,7 @@ MRP Repair Discount
===================
This module extends the functionality of mrp repair adding
new field discount on operation's lines
new field discount on operations lines
Usage
=====
@@ -27,16 +27,12 @@ help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Nicola Malcontenti <nicola.malcontenti@agilebg.com>
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
Maintainer
----------

View File

@@ -12,10 +12,10 @@
"Tecnativa, "
"Odoo Community Association (OCA)",
"website": "http://www.agilebg.com",
"contributors": [
"Nicola Malcontenti <nicola.malcontenti@gmail.com>",
],
'depends': ['mrp_repair'],
"data": ["views/mrp_repair_view.xml"],
"test": [
'test/mrp_repair_discount.yml',
],
"installable": True,
}

View File

@@ -42,3 +42,62 @@ class MrpRepair(models.Model):
if operations:
repair.invoice_id.button_reset_taxes()
return res
def _calc_line_base_price(self, line):
return line.price_unit * (1 - (line.discount or 0.0) / 100.0)
def _get_lines(self, cr, uid, ids, context=None):
return self.pool['mrp.repair'].search(
cr, uid, [('operations', 'in', ids)], context=context)
def _get_fee_lines(self, cr, uid, ids, context=None):
return self.pool['mrp.repair'].search(
cr, uid, [('fees_lines', 'in', ids)], context=context)
def _amount_tax(self, cr, uid, ids, field_name, arg, context=None):
# Can't call super because we have to call compute_all with different
# parameter for each line and compute the total amount
res = {}
cur_obj = self.pool.get('res.currency')
tax_obj = self.pool.get('account.tax')
for repair in self.browse(cr, uid, ids, context=context):
val = 0.0
cur = repair.pricelist_id.currency_id
for line in repair.operations:
if line.to_invoice:
tax_calculate = tax_obj.compute_all(
cr, uid, line.tax_id, self._calc_line_base_price(line),
line.product_uom_qty, line.product_id,
repair.partner_id)
for c in tax_calculate['taxes']:
val += c['amount']
for line in repair.fees_lines:
if line.to_invoice:
tax_calculate = tax_obj.compute_all(
cr, uid, line.tax_id, line.price_unit,
line.product_uom_qty, line.product_id,
repair.partner_id)
for c in tax_calculate['taxes']:
val += c['amount']
res[repair.id] = cur_obj.round(cr, uid, cur, val)
return res
_columns = {
'amount_tax': old_fields.function(
_amount_tax, string='Taxes',
store={
'mrp.repair': (
lambda self, cr, uid, ids, c={}: ids,
['operations', 'fees_lines'], 10),
'mrp.repair.line': (
_get_lines, [
'price_unit', 'price_subtotal', 'product_id', 'tax_id',
'product_uom_qty', 'product_uom', 'discount',
], 10),
'mrp.repair.fee': (
_get_fee_lines, [
'price_unit', 'price_subtotal', 'product_id', 'tax_id',
'product_uom_qty', 'product_uom'
], 10),
}),
}

View File

@@ -0,0 +1,48 @@
-
I create a Tax Codes
-
!record {model: account.tax.code, id: tax_case}:
name: Tax_case
company_id: base.main_company
sign: 1
-
I create a Tax
-
!record {model: account.tax, id: tax10}:
name: Tax 10 %
amount: 0.1
type: percent
sequence: 1
company_id: base.main_company
type_tax_use: all
tax_code_id: tax_case
-
!record {model: mrp.repair, id: mrp_repair_discount}:
address_id: base.res_partner_address_1
guarantee_limit: !eval datetime.today().strftime("%Y-%m-%d")
invoice_method: 'none'
product_id: product.product_product_3
product_uom: product.product_uom_unit
partner_invoice_id: base.res_partner_address_1
location_dest_id: stock.stock_location_14
location_id: stock.stock_location_stock
operations:
- location_dest_id: stock.location_production
location_id: stock.stock_location_stock
name: '[M-Las] Mouse, Laser'
price_unit: 50.0
product_id: product.product_product_11
product_uom: product.product_uom_unit
product_uom_qty: 1.0
state: draft
to_invoice: 1
type: add
discount: 10
tax_id:
- tax10
partner_id: base.res_partner_9
-
I check the total amount of mrp_repair_rmrp1 is 49.5
-
!assert {model: mrp.repair, id: mrp_repair_discount, string=amount_total should be 49.5}:
- amount_total == 49.5