Odoo在python中编程地向采购订单添加税收

2024-05-15 10:04:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从外部源(在线xml请求)创建采购订单。 当我循环检查每个订单时,我创建一个采购订单,然后循环检查产品并为每个产品创建一个订单行。在

除了增加税收外,所有这些都起作用了。我对如何增加税收感到困惑。我是否应该像这样立即将值添加到采购订单->

# Create orderline foreach product (this happens in the loop foreach product)
orderlineList =  {
                'name': itemText,
                'product_id': itemId,
                'product_qty': itemOrdered,
                'product_uom': 1,
                'price_unit': itemPrice,
                'date_planned': orderDatePlanned,
            }

            struct = orderlinetuple + (orderlineList,)
            po_vals.append(struct)

 #This adds all the orderlines into 'order_line'
  orderDict = { 
         'amount_untaxed' : totalNet,
         'amount_tax': totalTax,
         'partner_id': api_partner,
         'amount_total' : totalBrut,
         'order_line': po_vals,
     }
# Then we create the purchase order with the added orderlines in one go
  self.PurchaseOrder = self.env['purchase.order']   
  po_id = self.PurchaseOrder.create(orderDict)

如果我像这样创建我的采购订单,amount_tax和amount_total被忽略,我只是从没有税的订单行中获取总数。在

这是不是走错了路?我读过关于在采购订单上调用onchange的文章,但我不确定这是如何工作的,因为我不知道这将如何增加税收

此图显示订单行不含税 enter image description here

这张图显示订单没有税 enter image description here

简而言之,在python中从后端创建采购订单时,如何向订单添加税金(例如21%)。在

感谢那个能为我指明正确方向的人,在过去的3天里一直在努力寻找这个方向。。。在


Tags: thein订单selfid产品orderproduct
1条回答
网友
1楼 · 发布于 2024-05-15 10:04:21

您需要调用odoo的default更改方法。

When you call on-change method then system will automatic set tax based on product default tax and purchase order fiscal position.

第1步:您需要在不添加任何订单行的情况下创建采购订单

在自我.env['采购订单'].create({'partner_id':'',…})

第2步:使用以下方法创建所有采购订单行。在

    new_record=self.env['purchase.order.line'].new({'order_id':purchase_order.id,
              'product_id':product_id,
              'product_uom':uom+id,
              'name':product_name
              })

    new_record.onchange_product_id()
    order_vals=new_record._convert_to_write({name: new_record[name] for name in new_record._cache}) 
    order_vals.update({'product_qty':product_qty,'price_unit':price_unit})
    self.env['purchase.order.line'].create(order_vals)

步骤2中,我们创建了采购订单行并调用onchange_product_id方法。根据采购订单的会计状况和产品的默认税自动计算税款。在

这可能对你有帮助。在

相关问题 更多 >