Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


ODOO-8: Cannot write FLEET_ID field to invoice (from MRP REPAIR)

Mohammed Kamar-eddine
on 7/1/16, 2:10 PM 134 views

Ok so the update now is that i dont receive any more errors (500-error and null value)

But the invoice doesn't get updated with the vehicle[fleet_id] from MRP repair when the button is clicked


The code i've added so far - MRP_REPAIR.PY

def action_invoice_create(self, cr, uid, ids, group=False, context=None):

print "action_invoice_create---------------",ids, group, context

context = dict(context or {})

repair = self.browse(cr, uid, ids[0], context)

context['default_fleet_id'] = repair.fleet_id and repair.fleet_id.id or False

res = super(mrp_repair, self).action_invoice_create(cr, uid, ids,



inv_line_obj = self.pool.get('account.invoice.line')

inv_obj = self.pool.get('account.invoice')

for repair_id, invoice_id in res.iteritems():

if not invoice_id:


invoice = inv_obj.browse(cr, uid, invoice_id) #deactivated by MSKE-30/06/2016

inv_obj.write(cr, uid, [invoice_id],{'fleet_id': fleet_id}) # added by MSKE-25/06/2016

for rsol in repair.order_line_ids:

name = rsol.name or ''

if rsol.product_id.property_account_income:

account_id = rsol.product_id.property_account_income.id

elif rsol.product_id.categ_id.property_account_income_categ:

account_id = rsol.product_id.categ_id.property_account_income_categ.id


raise osv.except_osv(_('Error!'), _('No account defined for product "%s".') % rsol.product_id.name)

invoice_line_vals = {

'invoice_id': invoice_id,

'name': rsol.product_id.name,

'origin': rsol.repair_sale_order_line_id.name,

'account_id': account_id,

'quantity': rsol.product_uom_qty, #enabled MSKE-30/06/2016

'invoice_line_tax_id': [(6, 0, [x.id for x in rsol.tax_id])],

'uos_id': rsol.product_id.uom_id.id,

'price_unit': rsol.price_unit,

'price_subtotal': rsol.product_uom_qty * rsol.price_unit,

'product_id': rsol.product_id and rsol.product_id.id or False


print "invoice_line_vals----------",invoice_line_vals

invoice_line_id = inv_line_obj.create(cr, uid, invoice_line_vals)

print "after line create----------------------------",invoice_line_id


button_reset_taxes(cr, uid, invoice_id, context=context)

return res


_columns = {

'sale_id': fields.many2one('sale.order', 'Quotation', readonly=True),

# Devis

'livraison_id': fields.many2one('garage.livraison', 'Delivery Report',


# Procès de livraison

'fleet_id': fields.many2one('fleet.vehicle', 'Vehicle', required=True,

readonly=True), # Vehicle

'product_id': fields.many2one('product.product',

string='Product to Repair',


states={'draft': [

('readonly', False)]}),

def action_repair_done(self, cr, uid, ids, context=None):

print "action_repair_done-------------------",ids, context

res = {}

move_obj = self.pool.get('stock.move')

repair_line_obj = self.pool.get('mrp.repair.line')

reception_obj = self.pool.get('garage.reception')

for repair in self.browse(cr, uid, ids, context=context):

move_ids = []

for move in repair.operations:

repair_line_obj.write(cr, uid,

[move.id], {'state': 'done'},


self.write(cr, uid, [repair.id], {'state': 'done'},


if repair.reception_id:

print "repair.reception_id-----------",repair.reception_id

reception_obj.write(cr, uid, [repair.reception_id.id],

{'state': 'termine'}, context=context)

if repair:

this = repair

reception_id = this.reception_id or None

vals = {

'name': None,

'partner_id': this.partner_id and this.partner_id.id or


'reception_id': reception_id.id,

'partner_recived_from': reception_id and





or None,

'responsable_id': reception_id and

reception_id.responsable_id and

reception_id.responsable_id.id or None,

'fleet_id': this.fleet_id and this.fleet_id.id or None,

'kilometrage': reception_id.kilometrage,

'state': 'en_cours',

'datetime_livraison': time.strftime('%Y-%m-%d %H:%M:%S'),



if this.service_requested_ids:

vals.update({'service_done_ids' : [(6, 0, [service_id.id for service_id in this.service_requested_ids])] })

livraison_id = self.pool.get('garage.livraison').\

create(cr, uid, vals, context=context)

self.write(cr, uid, [this.id],

{'livraison_id': livraison_id}, context=context)

# ********************************

return True

code from INVOICE.PY


class account_invoice(models.Model):

_inherit = "account.invoice"

def _get_subtotal_word(self, cr, uid, ids, name, arg, context=None):

res = {}

for sale in self.browse(cr, uid, ids, context=context):

res[sale.id] = self.convert_int_ot_word(sale.amount_total).\


return res

_columns = {

'subtotal_word': fields.function(_get_subtotal_word, type='char',


'reception_id': fields.many2one('garage.reception',

'Reception Report', readonly=True),

# Procèss de reception

# 'fleet_id': fields.related('reception_id', 'fleet_id',

# relation='fleet.vehicle',

# string='Vehicles',

# type='many2one', readonly=True),

'fleet_id':fields.many2one('fleet.vehicle','Vehicles' ,readonly=True),

# Véhicules

'responsable_id': fields.many2one('res.users', 'Supervisor', readonly=True),

# Responsable


_defaults = {

'responsable_id' : lambda self, cr, uid, ctx=None: uid


def create(self, cr, uid, vals, context=None):

sale_order = self.pool.get('sale.order')

sale_order_data = sale_order.\

search(cr, uid, [('name', '=', vals['origin'])], context=context)

sale_order_id = sale_order.\

browse(cr, uid, sale_order_data, context=context)

vals['fleet_id'] = sale_order_id.fleet_id.id

res = super(account_invoice, self).create(cr, uid, vals, context)

return res

def action_move_create(self, cr, uid, ids, context=None):

for inv in self.browse(cr, uid, ids, context):

if not inv.journal_id.sequence_id:

raise except_orm(_('Error!'), _('Please define sequence'

'on the journal related to'

'this invoice.'))

if not inv.invoice_line:

raise except_orm(_('No Invoice Lines!'), _('Please create'

'some invoice'


if inv.move_id:


res = super(account_invoice, self).action_move_create(cr, uid, ids,


group_id = \


get_object_reference(cr, SUPERUSER_ID, 'garage',


group_brw = self.pool.get('res.groups').\

browse(cr, SUPERUSER_ID, group_id, context=context)

user_is_manager = False

for user in group_brw.users:

if user.id == uid:

user_is_manager = True

if not user_is_manager:

raise osv.except_osv(_('User Error!'),

_('Please contact your Manager to'

'confirm this invoice'))

return res


def invoice_print(self):

""" Print the invoice and mark it as sent, so that we can see more

easily the next step of the workflow


assert len(self) == 1, 'This option should only be used for' \

'a single id at a time.'

self.sent = True

return self.env['report'].get_action(self,


uclass account_invoice_line(osv.osv):

_inherit = 'account.invoice.line'

def create(self, cr, uid, vals, context=None):

print "IL CREATE vals-------------",vals

return super(account_invoice_line,self).create(cr, uid, vals, context)

def convert_amount_language(self, cr, uid, ids,amount,currency='Euro', context=None):


if lang=='en_US':

new_amount=amount_to_text(amount, currency)


new_amount = new_amount.replace('euro', 'DHs')

new_amount = new_amount.replace('Cent', 'CTs')

new_amount = new_amount.replace('Cents', 'CT')


return new_amount

if lang=='fr_FR':

french_amount=amount_to_text_fr(amount, currency)

french_amount = french_amount.replace('Euro', 'DHs')

french_amount = french_amount.replace('Cents', 'CTs')



french_amount = french_amount[0:french_length_start]+french_amount[french_length_start-1:].replace('Cent', 'CTs')

return french_amount

def _get_product_amount_h_t(self, cr, uid, ids, name, arg, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

res[line.id] = (line.price_unit - (line.price_unit *

line.discount / 100))

return res

def _get_amount_h_t(self, cr, uid, ids, name, arg, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

res[line.id] = (line.price_unit - (line.price_unit *

line.discount / 100)) # * line.product_uom_qty

return res

def _get_profit(self, cr, uid, ids, name, arg, context=None):

res = {}

for line in self.browse(cr, uid, ids, context=context):

res[line.id] = (line.price_unit -(line.price_unit * line.discount/100)) - line.product_id.standard_price

return res

def onchange_price_unit(self, cr, uid, ids, product_id, discount,

price_unit, context=None):

res = {}

if product_id:

product_brw = self.pool.get('product.product').\

browse(cr, uid, product_id, context=context)

return {'value': {'profit': (price_unit -

(price_unit * discount / 100)) -


return {}

_columns = {

'product_amount_h_t': fields.function(_get_product_amount_h_t,


string='Price excl. TAX'),

# Price h.t

'amount_h_t': fields.function(_get_amount_h_t, type='float',

string='Amount exl. tax'),

# Amount h.t

'type_product_id': fields.related('product_id', 'product_tmpl_id', 'type_product_id', type='many2one', relation='product.type',

string='Type Of Part', readonly=False ),

'profit': fields.function(_get_profit, type='float' , string='Profit'),


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 7/1/16, 2:10 PM
Seen: 134 times
Last updated: 7/1/16, 5:29 PM