从行中读取产品价格 - 将其写入会计日志 - Odoo v8

Read product price from lines - write it to accounting journal - Odoo v8

我需要从 One2many 字段中读取数量,然后根据记录的 state,将此数量注销到特定的日记帐。

这是我的模型:

class print_order(models.Model):
    _name = 'print.order'

    name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
    date = fields.Date(string="Print Date",default=fields.Datetime.now)
    production_orders = fields.Many2one('bsi.production.order', ondelete='cascade', string="Production Order")
    due_date = fields.Date(string="Due Date")
    journal_entry = fields.Many2one('account.move', string="Journal Entry")
    stock_picking_id = fields.Many2one('stock.picking', string="Stock Picking")
    order_picking = fields.One2many('print.order.lines', 'print_order', string="Order lines")
    book_block = fields.Boolean(string="Book Block", default=True, ) 
    binding = fields.Boolean(string="Binding", ) #compute="_bool_binding", readonly=False
    edging = fields.Boolean(string="Edging", ) #compute="_bool_edging", readonly=False
    raw_material_consumed = fields.One2many('stock.move', 'stock_move_lines', string="Raw material consumed")
    contract_worksheet = fields.One2many('mrp.worksheet.contract', 'printer_order', string="Worksheet calculation")
    name_contract = fields.Char(string="Name", compute="_compute_worksheet") 
    state = fields.Selection([
            ('draft','Draft'),
            ('inprogress','In progress'),
            ('awaitingraw','Awaiting raw materials'),
            ('work_in_progress','Print in Progress'),
            ('delivered','Delivered'),
            ('cancel','Cancel'),
        ], string="State")
    notes = fields.Text(string="Notes")
    printer_book_block = fields.Many2one('res.partner', string="Printer Book Block")
    printer_binding = fields.Many2one('res.partner', string="Printer Binding")
    printer_edging = fields.Many2one('res.partner', string="Printer Edging")
    transporter = fields.Many2one('res.partner', string="Transporter")
    total_transport_cost = fields.Float(string="Total transport cost")
    additional_job = fields.Boolean(string="Additional Job")
    company_id = fields.Many2one('res.company', 'Company',default='_default_company')
    location_id = fields.Many2one('stock.location', string="Source Location")
    location_dest_id = fields.Many2one('stock.location', string="Destination Location")

因此,isbn 是一个 Many2oneproduct.product 模型,在这个模型上我创建了一个新的 Many2one 字段到 account.account

如您所见,这个 class 有 'states',因此根据特定状态,我应该从 contract_worksheet 中写入这个数量,这是一个 One2many 字段,进入我在 product.productdebitcredit 字段上创建的特定期刊。

现在,让我感到困惑的是,如何访问 One2many 上的这些特定字段?

以及如何在状态之间切换时自动执行此操作?

这是我目前尝试过的方法:

@api.model
@api.depends('order_picking', 'order_picking.isbn', 'contract_worksheet')
def accounting_scenarios(self):
    for record in self:
        if self.state == awaitingraw:
            self.isbn.printer_wip_account.debit = self.contract_worksheet.total_alles

但它什么也没做。

那么,有什么想法吗?

编辑

这是我从 order_picking One2many 字段访问的模型:

class bsi_print_order_lines(models.Model):
    _name = 'bsi.print.order.lines'

    print_order = fields.Many2one('bsi.print.order', string="Print Order")
    isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
    qty = fields.Integer(string="Quantity")
    consumed_qty = fields.Integer(string="Quantity consumed")
    remaining_qty = fields.Float(string="Remaining quantity") #, compute="_remaining_func"
    is_book_block = fields.Boolean(string="Is Book Block Done", compute="compute_book_block")
    is_binding = fields.Boolean(string="Is Binding Done", compute="compute_binding")
    is_edging = fields.Boolean(string="Is Edging Done", compute="compute_edging")
    isbns = fields.Many2one('worksheets.isbns', string="Worksheet ISBNS")

我认为您应该使用 @api.multi 而不是 @api.model,因为您正在计算这些值。

此外,将 self 替换为 record,如下所示:

@api.multi
@api.depends('order_picking', 'order_picking.isbn', 'contract_worksheet')
def accounting_scenarios(self):
    for record in self:
        if record.state == 'awaitingraw':
            record.isbn.printer_wip_account.debit = record.contract_worksheet.total_alles