Odoo Help

Welcome!

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.

0

[8.0] Generating INVOICE from REPAIR ORDER - FLEET ID doesnt appear

By
Mohammed Kamar-eddine
on 6/24/16, 11:15 AM 310 views

Using ODOO v8, Creating INVOICE from REPAIR ORDER - the vehicle (fleet_id) doesnt get transferred to the final INVOICE. What lines could i include to the .py file under 'action_nvoice_create' to allow the vehicule in the repair order to be transferred to the INVOICE

				<button name="action_invoice_create" position="replace">
					<button name="action_invoice_create" states="2binvoiced" string="Create Invoice" class="oe_highlight" attrs="{'invisible':[('invoiced','=',True)]}" groups="garage.group_garage_manager" />
				</button>

.PY file of MRP_REPAIR

==========

    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)
            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

The invoice xml file displaying the fleet_id

		<record model="ir.ui.view" id="invoice_form">
			<field name="name">account.invoice.inherit</field>
			<field name="model">account.invoice</field>
			<field name="inherit_id" ref="account.invoice_form" />
			<field name="arch" type="xml">
				<field name="partner_id" position="after">
					<field name="responsable_id" />
					<field name="flt_id" string="Vehicles" />
				</field>
			</field>
		</record>

and the (.py) file of 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.related('reception_id', 'fleet_id',
                                   relation='fleet.vehicle',
                                   string='Vehicles123',
                                   type='many2one', readonly=True),
        'flt_id':fields.many2one('fleet.vehicle','Vehicles456' ,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['flt_id'] = sale_order_id.fleet_id.id
        res = super(account_invoice, self).create(cr, uid, vals, context)
        return res

Odoo Server Error

Traceback (most recent call last):

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 539, in _handle_exception

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 576, in dispatch

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 312, in _call_function

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 118, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 309, in checked_call

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 805, in __call__

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 405, in response_wrap

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\web\controllers\main.py", line 955, in exec_workflow

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 1113, in exec_workflow

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 881, in proxy_method

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 115, in dispatch_rpc

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 37, in dispatch

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 118, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 188, in exec_workflow

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 182, in exec_workflow_cr

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 164, in execute_cr

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\models.py", line 3571, in signal_workflow

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\__init__.py", line 85, in trg_validate

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\service.py", line 91, in validate

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\instance.py", line 80, in validate

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 120, in process

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 248, in _split_test

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 257, in _join_test

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 95, in create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 116, in process

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 162, in _execute

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 313, in wkf_expr_execute

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 291, in wkf_expr_eval_expr

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\tools\safe_eval.py", line 314, in safe_eval

File "", line 1, in <module>

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 266, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 564, in new_api

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\mrp_repair\mrp_repair.py", line 306, in wkf_invoice_create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\garage\objects\mrp_repair.py", line 558, in action_invoice_create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\mrp_repair\mrp_repair.py", line 351, in action_invoice_create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\garage\objects\invoice.py", line 50, in create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\mail\mail_thread.py", line 381, in create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 372, in old_api

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\models.py", line 4093, in create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 266, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 508, in new_api

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\models.py", line 4231, in _create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\sql_db.py", line 158, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\sql_db.py", line 234, in execute

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()'

Mohammed Kamar-eddine
on 6/25/16, 10:55 AM
0
Mohammed Kamar-eddine
On 6/25/16, 10:11 AM

def action_invoice_create(self, cr, uid, ids, group=False, context=None):
    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, group=group, context=context)

I've added the code listed above, which resulted in this code below:


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['fleet_id'] = repair.fleet_id and repair.fleet_id.id or False
    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

But i'm receiving the error:

ValueError: "null value in column "fleet_id" violates not-null constraint

Any advice? Where did i go wrong

THE ERROR im receiving now:

Odoo Server Error

Traceback (most recent call last):

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 539, in _handle_exception

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 576, in dispatch

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 312, in _call_function

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 118, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 309, in checked_call

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 805, in __call__

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 405, in response_wrap

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\web\controllers\main.py", line 955, in exec_workflow

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 1113, in exec_workflow

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 881, in proxy_method

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\http.py", line 115, in dispatch_rpc

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 37, in dispatch

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 118, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 188, in exec_workflow

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 182, in exec_workflow_cr

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\service\model.py", line 164, in execute_cr

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\models.py", line 3571, in signal_workflow

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\__init__.py", line 85, in trg_validate

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\service.py", line 91, in validate

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\instance.py", line 80, in validate

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 120, in process

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 248, in _split_test

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 257, in _join_test

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 95, in create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 116, in process

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 162, in _execute

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 313, in wkf_expr_execute

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\workflow\workitem.py", line 291, in wkf_expr_eval_expr

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\tools\safe_eval.py", line 314, in safe_eval

File "", line 1, in <module>

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 266, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 564, in new_api

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\mrp_repair\mrp_repair.py", line 306, in wkf_invoice_create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\garage\objects\mrp_repair.py", line 558, in action_invoice_create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\mrp_repair\mrp_repair.py", line 351, in action_invoice_create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\garage\objects\invoice.py", line 50, in create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\openerp\addons\mail\mail_thread.py", line 381, in create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 268, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 372, in old_api

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\models.py", line 4093, in create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 266, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\api.py", line 508, in new_api

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\models.py", line 4231, in _create

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\sql_db.py", line 158, in wrapper

File "C:\Program Files (x86)\Odoo 8.0-20160420\server\.\openerp\sql_db.py", line 234, in execute

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()'

Mohammed Kamar-eddine
on 6/25/16, 10:55 AM
0
ayman mohammed adam
On 6/25/16, 5:32 AM

Dear all,

you must add 

fleet_id field  many2one on account.invoice Model and then update this field on created invoice  



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)
                        inv_obj.write(cr, uid, [invoice_id],{'fleet_id':your fleet _id})

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)

Stats

Asked: 6/24/16, 11:15 AM
Seen: 310 times
Last updated: 6/25/16, 10:11 AM