mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[FIX] Fixed functional method
This commit is contained in:
@@ -2,14 +2,28 @@
|
||||
# © 2015 Nicola Malcontenti - Agile Business Group
|
||||
# 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.osv import orm, fields
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
|
||||
class MrpRepairLine(models.Model):
|
||||
class MrpRepairLine(orm.Model):
|
||||
_inherit = 'mrp.repair.line'
|
||||
|
||||
discount = fields.Float(string='Discount (%)')
|
||||
def _amount_line(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = super(MrpRepairLine, self)._amount_line(
|
||||
cr, uid, ids, field_name, arg, context=None)
|
||||
for line in self.browse(cr, uid, ids, context=context):
|
||||
price = res[line.id] * (1 - (line.discount or 0.0) / 100.0)
|
||||
res[line.id] = price
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'discount': fields.float(string='Discount (%)'),
|
||||
'price_subtotal': fields.function(
|
||||
_amount_line, string='Subtotal',
|
||||
digits_compute=dp.get_precision('Account')),
|
||||
|
||||
}
|
||||
|
||||
|
||||
class MrpRepair(orm.Model):
|
||||
@@ -18,7 +32,9 @@ class MrpRepair(orm.Model):
|
||||
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
|
||||
repair = self.browse(cr, uid, ids, context=context)
|
||||
for op in repair.operations:
|
||||
if op.to_invoice:
|
||||
op.invoice_line_id.discount = op.discount
|
||||
repair.invoice_id.button_reset_taxes()
|
||||
return res
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<field name="model">mrp.repair</field>
|
||||
<field name="inherit_id" ref="mrp_repair.view_repair_order_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='operations']/tree/field[@name='price_subtotal']" position='before'>
|
||||
<xpath expr="//field[@name='operations']/tree/field[@name='price_unit']" position='after'>
|
||||
<field name="discount"/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user