diff --git a/addons/mrp_repair/__openerp__.py b/addons/mrp_repair/__openerp__.py index 26480e975ce..6f324c43f7a 100644 --- a/addons/mrp_repair/__openerp__.py +++ b/addons/mrp_repair/__openerp__.py @@ -56,7 +56,8 @@ The following topics should be covered by this module: 'test/test_mrp_repair_b4inv.yml', 'test/test_mrp_repair_afterinv.yml', 'test/test_mrp_repair_cancel.yml', - 'test/mrp_repair_report.yml' + 'test/mrp_repair_report.yml', + 'test/test_mrp_repair_fee.yml', ], 'installable': True, 'auto_install': False, diff --git a/addons/mrp_repair/mrp_repair.py b/addons/mrp_repair/mrp_repair.py index 9c0ab0e2c18..fb7fd4ab71b 100644 --- a/addons/mrp_repair/mrp_repair.py +++ b/addons/mrp_repair/mrp_repair.py @@ -109,10 +109,12 @@ class mrp_repair(osv.osv): return res def _get_lines(self, cr, uid, ids, context=None): - result = {} - for line in self.pool.get('mrp.repair.line').browse(cr, uid, ids, context=context): - result[line.repair_id.id] = True - return result.keys() + 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) _columns = { 'name': fields.char('Repair Reference',size=24, required=True, states={'confirmed':[('readonly',True)]}), @@ -163,16 +165,19 @@ class mrp_repair(osv.osv): store={ 'mrp.repair': (lambda self, cr, uid, ids, c={}: ids, ['operations'], 10), 'mrp.repair.line': (_get_lines, ['price_unit', 'price_subtotal', 'product_id', 'tax_id', 'product_uom_qty', 'product_uom'], 10), + 'mrp.repair.fee': (_get_fee_lines, ['price_unit', 'price_subtotal', 'product_id', 'tax_id', 'product_uom_qty', 'product_uom'], 10), }), 'amount_tax': fields.function(_amount_tax, string='Taxes', store={ 'mrp.repair': (lambda self, cr, uid, ids, c={}: ids, ['operations'], 10), 'mrp.repair.line': (_get_lines, ['price_unit', 'price_subtotal', 'product_id', 'tax_id', 'product_uom_qty', 'product_uom'], 10), + 'mrp.repair.fee': (_get_fee_lines, ['price_unit', 'price_subtotal', 'product_id', 'tax_id', 'product_uom_qty', 'product_uom'], 10), }), 'amount_total': fields.function(_amount_total, string='Total', store={ 'mrp.repair': (lambda self, cr, uid, ids, c={}: ids, ['operations'], 10), 'mrp.repair.line': (_get_lines, ['price_unit', 'price_subtotal', 'product_id', 'tax_id', 'product_uom_qty', 'product_uom'], 10), + 'mrp.repair.fee': (_get_fee_lines, ['price_unit', 'price_subtotal', 'product_id', 'tax_id', 'product_uom_qty', 'product_uom'], 10), }), } diff --git a/addons/mrp_repair/test/test_mrp_repair_fee.yml b/addons/mrp_repair/test/test_mrp_repair_fee.yml new file mode 100644 index 00000000000..6aac605d0d9 --- /dev/null +++ b/addons/mrp_repair/test/test_mrp_repair_fee.yml @@ -0,0 +1,23 @@ +- + Testing total amount update function +- + I check the total amount of mrp_repair_rmrp1 is 100 +- + !assert {model: mrp.repair, id: mrp_repair_rmrp1, string=amount_total should be 100}: + - amount_total == 100 +- + I add a new fee line +- + !record {model: mrp.repair, id: mrp_repair_rmrp1}: + fees_lines: + - name: 'Assembly Service Cost' + product_id: product.product_assembly + product_uom_qty: 1.0 + product_uom: product.product_uom_hour + price_unit: 12.0 + to_invoice: True +- + I check the total amount of mrp_repair_rmrp1 is now 112 +- + !assert {model: mrp.repair, id: mrp_repair_rmrp1, string=amount_total should be 112}: + - amount_total == 112