Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
10883 มุมมอง

create 2 new fields in sale order and invoice lines as  “Order Type” and “Staff”.  When Creating Customer Invoice, pass the value of “Order Type”, “Staff” from SO to the corresponding fields in all invoice lines..

class SaleOrderForm(models.Model):
     _inherit = "sale.order"
     order_type = fields.Many2one('account.analytic.account', string='Order Type)
     staff = fields.Many2one('account.analytic.account', string='Staff', required=True)

     def _prepare_invoice(self, cr, uid, order, lines, context=None):
            self.pool.get('account.invoice.line').write(cr, uid, lines, {'order_type': order.order_type.id, 'staff': order.staff.id})
        return super(so_form, self)._prepare_invoice(cr, uid, order, lines, context=None)

This is a working code. but i just need it in new api. please help me.. Thanks in advance.
อวตาร
ละทิ้ง

I don't no value of lines, ids invoice_line [1,2,3,4] or object invoice_line (account.invoice.line(1,2,3,4))?

คำตอบที่ดีที่สุด

Try this, It will work..


@api.modeldef _prepare_invoice(self, order, lines):
 print "****************Invoice Gen*****************"
print order.order_type.name
print lines
res = super(so_form, self)._prepare_invoice(order, lines)
if lines:
    for i in lines:
        self.env['account.invoice.line'].search([('id', '=', i)]).write({'order_type': order.order_type.id, 'staff':order.staff.id})
return res
อวตาร
ละทิ้ง
ผู้เขียน

Thanks

คำตอบที่ดีที่สุด

Try this :

@api.multi
def _prepare_invoice(self, order, lines):
    self.env['account.invoice.line'].write(self._cr, self._uid, lines, {'order_type': order.order_type.id, 'staff': order.staff.id})
 return super(so_form, self)._prepare_invoice(order, lines)
อวตาร
ละทิ้ง
ผู้เขียน

Thanks

Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ก.ค. 18
4012
4
ธ.ค. 15
11558
0
พ.ค. 20
3015
2
ธ.ค. 18
27557
2
มิ.ย. 15
3913