如何计算Odoo中供应商账单中的借方,贷方金额?

问题描述

我是Odoo Accounting的新手。我在计算卖方帐单的借方和贷方金额时遇到问题。我在采购订单行中添加了两个新字段,Discount_type和Discount_amt。小计值必须为(price_unit *数量)-折扣。我可以计算小计金额。但是,当我检查日记帐项目时,借方和贷方金额没有更改。我的意思是折扣金额未扣除。但是,当我保存表格时,出现了错误,指出借方和贷方不平衡。我该怎么办?

    def compute_price_subtotal(self):

    for line in self:

        line.discount_type = line.purchase_line_id.discount_type
        line.discount_amt = line.purchase_line_id.discount_amt

        qty = line.quantity or 0
        price_unit = line.price_unit or 0

        subtotal = price_unit * qty

        discount_type = line.discount_type
        discount_amount = line.discount_amt

        if discount_type == 'fixed':
            discount = discount_amount * qty
            line.price_subtotal = subtotal - discount

        elif discount_type == 'percentage':
            discount = subtotal * (discount_amount / 100)
            line.price_subtotal = subtotal - discount

        else:
            line.price_subtotal = subtotal

        if line.move_id.type in line.move_id.get_outbound_types():
            sign = 1
        elif line.move_id.type in line.move_id.get_inbound_types():
            sign = -1
        else:
            sign = 1

        price_subtotal = sign * line.price_subtotal

        line.update({
            'debit': price_subtotal > 0.0 and price_subtotal or 0.0,'credit': price_subtotal < 0.0 and -price_subtotal or 0.0,})

以上方法是计算价格小计,借方和贷方。

enter image description here

在图中,未税金额为13800,税额为690。因此,总金额为13800 + 690 =14490。但是在日记帐项目中,它显示了15000,小计值也不同。

enter image description here

解决方法

这是因为您只修改了您感兴趣的行。 这会尝试修改借方/贷方,但它会使帐户移动不平衡。 由于这违反了约束,因此阻止了会计的修改。

在更新任何内容之前,您需要平衡移动。 这也涉及更新税收行和应付/应收行。 获得所有这些行后,您可以更新整个帐户移动。

这意味着你必须做这样的事情: (假设计算已经完成)


lines_to_write = [
    (1,line_A_id,line_A_values),(1,tax_line_id,tax_line_values),receivable_line_id,receivable_line_values)
]
move.write({'line_ids': lines_to_write})

你可以得到命令列表here

顺便说一句,要在更改业务字段时重新计算借方和贷方,您可以(应该)调用方法 _get_fields_onchange_subtotal_model 以获取新值,然后使用这些新值更新帐户移动行。

原因之一是会计和发票可能使用不同的货币。

免责声明:仅当您确定自己在做什么时才应修改税费。 这可能会影响用户的税务报告。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...