我有这个方法:
@api.multi
@api.depends('order_picking', 'order_picking.isbn', 'contract_worksheet', 'state')
def accounting_scenarios(self):
for record in self:
if not len(record.transporter):
raise Warning('Please Enter Transporter !')
elif not len(record.transporter.transp_transit):
raise Warning('Please assign transit account to the transporter !')
if record.state in ('awaitingraw'): #('cancel', 'done')
acc_move = self.env['account.move']
move_lines = [
(0, 0, {
'name': 'name',
'debit': record.contract_worksheet.total_alles,
'credit': record.contract_worksheet.total_alles,
'account_id': record.transporter.transp_transit,
'date': date,
'partner_id': record.transporter,
}),
]
acc_move.create({
#'period_id': period_id,
'journal_id': record.transporter.journal_id.id,
'date':date,
'state': 'draft',
'line_id': move_lines, # this is one2many field to account.move.line
})
elif record.state in ('work_in_progress'):
record.temp2 = record.contract_worksheet.total_totals
elif record.state in ('delivered'):
record.transporter.transp_transit.debit = record.contract_worksheet.total_alles
它抛出了我:
Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 948, in call_button
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 399, in old_api
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\bsi\models\models.py", line 1471, in check_quantity
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\bsi\models\models.py", line 1399, in write
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 3789, in write
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 592, in new_api
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 4048, in _write
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 5773, in recompute
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 5773, in <dictcomp>
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\models.py", line 5654, in __getitem__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\fields.py", line 835, in __get__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\fields.py", line 913, in determine_value
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\fields.py", line 893, in compute_value
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\fields.py", line 885, in _compute_value
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 266, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\bsi\models\models.py", line 1386, in accounting_scenarios
AttributeError: 'res.partner' object has no attribute 'journal_id'
此行journal_id': record.transporter.journal_id.id,
出现错误,如何从res.partner
分配日记?
我的意思是,它已分配了一个帐户(Many2one to account.account
),但我如何知道分配给该帐户的日记帐?并在此方法上指定它?
有什么想法吗?
修改
违规字段:
transporter = fields.Many2one('res.partner', string="Transporter", domain="[('type_of_supplier','=','transporter')]")
答案 0 :(得分:1)
问题是res.partner
模型没有任何journal_id
字段,因此您必须从分配给合作伙伴的帐户中获取该字段。这取决于您是否向运输商支付或出售某些服务。
如果您要向运输商支付一些服务(我猜是这样的话):
@api.multi
@api.depends('order_picking', 'order_picking.isbn', 'contract_worksheet', 'state')
def accounting_scenarios(self):
for record in self:
if not len(record.transporter):
raise Warning('Please Enter Transporter !')
elif not len(record.transporter.transp_transit):
raise Warning('Please assign transit account to the transporter !')
if record.state in ('awaitingraw'): #('cancel', 'done')
acc_move = self.env['account.move']
move_lines = [
(0, 0, {
'name': 'name',
'debit': record.contract_worksheet.total_alles,
'credit': record.contract_worksheet.total_alles,
'account_id': record.transporter.transp_transit,
'date': date,
'partner_id': record.transporter,
}),
]
journal_id = False
if record.transporter.property_account_payable:
journals = self.env['account.journal'].search([
('default_debit_account_id', '=', record.transporter.property_account_payable.id)
])
if journals:
journal_id = journals[0].id
acc_move.create({
#'period_id': period_id,
'journal_id': journal_id,
'date':date,
'state': 'draft',
'line_id': move_lines, # this is one2many field to account.move.line
})
elif record.state in ('work_in_progress'):
record.temp2 = record.contract_worksheet.total_totals
elif record.state in ('delivered'):
record.transporter.transp_transit.debit = record.contract_worksheet.total_alles
但是,如果你向他们出售一些服务:
@api.multi
@api.depends('order_picking', 'order_picking.isbn', 'contract_worksheet', 'state')
def accounting_scenarios(self):
for record in self:
if not len(record.transporter):
raise Warning('Please Enter Transporter !')
elif not len(record.transporter.transp_transit):
raise Warning('Please assign transit account to the transporter !')
if record.state in ('awaitingraw'): #('cancel', 'done')
acc_move = self.env['account.move']
move_lines = [
(0, 0, {
'name': 'name',
'debit': record.contract_worksheet.total_alles,
'credit': record.contract_worksheet.total_alles,
'account_id': record.transporter.transp_transit,
'date': date,
'partner_id': record.transporter,
}),
]
journal_id = False
if record.transporter.property_account_receivable:
journals = self.env['account.journal'].search([
('default_credit_account_id', '=', record.transporter.property_account_receivable.id)
])
if journals:
journal_id = journals[0]
acc_move.create({
#'period_id': period_id,
'journal_id': journal_id,
'date':date,
'state': 'draft',
'line_id': move_lines, # this is one2many field to account.move.line
})
elif record.state in ('work_in_progress'):
record.temp2 = record.contract_worksheet.total_totals
elif record.state in ('delivered'):
record.transporter.transp_transit.debit = record.contract_worksheet.total_alles