我想与大家分享有关我的代码的问题。因此,在这种情况下,我想在验证领料后立即在供应商账单上创建自动化。因此,在验证了入库货件后,它将自动填写供应商账单,同时也自动验证供应商账单。 (因此,我不需要手动单击供应商账单来创建它)。这就是目标。
我认为我已经可以填写表格了,但是我在invoice_line_ids字段上遇到了问题,该字段具有account_id作为必填字段。 这是我下面的功能:
from odoo import api, models, fields
class StockPicking(models.Model):
_inherit = 'stock.picking'
@api.multi
def button_validate(self):
res = super(StockPicking, self).button_validate()
action = self.env.ref('account.action_vendor_bill_template')
result = action.read()[0]
invoice_line_ids = []
loop = self.purchase_id.order_line
for line in loop:
inv_line_vals = [0, False]
inv_line = {
'product_id' : line.product_id.id,
'name' : line.name,
'quantity' : line.product_qty,
'price_unit' : line.price_unit,
'discount' : float(line.discount),
'invoice_line_tax_ids' : [(6, 0,line.taxes_id.ids)],
'price_subtotal' : line.price_subtotal,
'account_id' : line.id,
}
inv_line_vals.append(inv_line)
invoice_line_ids.append(inv_line_vals)
result = {
'type': 'in_invoice',
'purchase_id': self.purchase_id.id,
'currency_id': self.purchase_id.currency_id.id,
'company_id': self.purchase_id.company_id.id,
'partner_id': self.purchase_id.partner_id.id,
'date_invoice': self.move_ids_without_package.date_expected.strftime("%Y-%m-%d"),
'origin' : self.purchase_id.name,
'reference' : self.purchase_id.partner_ref,
'company_id': self.company_id.id,
'invoice_line_ids' : tuple(invoice_line_ids),
}
bils = self.env['account.invoice'].create(result)
bils.action_invoice_open()
return res
出现的警告错误:
Odoo服务器错误
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set
[object with reference: Account - account.account]