The error im receiving:
ValueError: "null value in column "fleet_id" violates not-null constraint
DETAIL: Failing row contains (2, null, null, 0.00, null, null, null, null, 1, 113, 2016-06-25 14:54:53.655, 1, null, null, null, 296, null, none, 2, null, draft, null, out_invoice, null, 1179, f, null, null, null, null, 2016-06-25 14:54:53.655, 1, 1, OR-003, null, OR-003, f, null, null, 1, null, null, null).
" while evaluating
u'wkf_invoice_create()'
I am trying to write a field of vehicles (fleet_id) from MRP_REPAIR file to INVOICE in ODOO-8:
The code i've added so far
invoice = inv_obj.browse(cr, uid, invoice_id)
inv_obj.write(cr, uid, [invoice_id],{'fleet_id': fleet_id})
these blocks are added to the function [action_invoice_create] in MRP_REPAIR.PY
def action_invoice_create(self, cr, uid, ids, group=False, context=None):
print "action_invoice_create---------------",ids, group, context
repair = self.browse(cr, uid, ids[0])
res = super(mrp_repair, self).action_invoice_create(cr, uid, ids,
group=group,
context=context)
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:
continue
invoice = inv_obj.browse(cr, uid, invoice_id) #activated by MSKE-25/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
else:
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,
'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
self.pool.get('account.invoice').
button_reset_taxes(cr, uid, invoice_id, context=context)
return res
I appreciate your help.
edit - here is some of the code in the 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).
upper()
return res
_columns = {
'subtotal_word': fields.function(_get_subtotal_word, type='char',
string='subtotal_word'),
'reception_id': fields.many2one('garage.reception',
'Reception Report', readonly=True),
# Procèss de reception
'fleet_id': fields.many2one('fleet.vehicle', 'VehicleMSKE', required=True,
readonly=True), # Vehicle
# Véhicules
'responsable_id': fields.many2one('res.users', 'Supervisor', readonly=True),
# Responsable
}
Value for the fleet_id:
'fleet_id': this.fleet_id and this.fleet_id.id or None,
located in the block (mrp_repair.py)
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'},
context=context)
self.write(cr, uid, [repair.id], {'state': 'done'},
context=context)
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
# MSKE DEACTIVATED Bottom lines to alert when RO has no order lines
# if (not this.sale_id) or (not this.sale_id.order_line):
# raise osv.except_osv(_('User Error!'),
# _("You must need add minimum single operation line for creation of invoice."))
reception_id = this.reception_id or None
vals = {
'name': None,
'partner_id': this.partner_id and this.partner_id.id or
None,
'reception_id': reception_id.id,
'partner_recived_from': reception_id and
reception_id.partner_recived_from
and
reception_id.
partner_recived_from.id
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'),
'repair_id':this.id,
}
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
Aucun commentaire:
Enregistrer un commentaire