python - Odoo自定义模块修复税收订单行?
问题描述
我是 Odoo 用户(不是开发人员)。我有一个有 2 个错误的自定义模块,我试图了解如何修复错误,但我没有找到解决方案。我认为感兴趣的代码在模型文件中。模块,通过在自定义字段中扫描条形码,在订单中添加产品线,包括产品、描述、数量、单价,但缺少税金。如果相同的产品条码被扫描更多时间,则在相同的产品线中增加数量。第一个错误问题是不加税,我有一条不含税的产品线。我看过里面的代码,并没有任何调用税收的命令。第二个错误问题是持有价格。该模块允许通过自定义字段条码扫描手动添加和更新价格,并且在代码内部有保持最后价格值更新的命令。没有这个,如果再次扫描产品,回到 odoo 价格。
------------第一部分代码:
# added the price history map
priceHistory = {}
class SaleOrder(models.Model):
"""Inherit Sale Order."""
_inherit = "sale.order"
barcode = fields.Char(string='Barcode', size=50)
def _add_product(self, product, qty, price):
"""Add line or update qty and price based on barcode."""
corresponding_line = self.order_line.filtered(lambda r: r.product_id.id == product.id)
if corresponding_line:
corresponding_line[0].product_uom_qty += float(qty)
corresponding_line[0].price_unit = float(price) or product.list_price
else:
self.order_line += self.order_line.new({
'product_id': product.id,
'product_uom_qty': qty,
'name': product.name,
'product_uom': product.uom_id.id,
'price_unit': float(price) or product.list_price,
})
return True
在这里,我尝试添加:
'tax_id' : account.tax
下线
'price_unit': float(price) or product.list_price,
但不工作。
------------ 最后的代码部分
if product_id:
# get the history price
if price_position == -1:
#if priceHistory.has_key(product_id.id):
if product_id.id in priceHistory.keys():
price = priceHistory[product_id.id]
self._add_product(product_id, qty, price)
self.barcode = barcode = None
#save the product price
priceHistory[product_id.id] = price
return
在这里,如果我删除:
#save the product price
priceHistory[product_id.id] = price
我可以解决保留价格值的问题,但我创建了一个新问题:如果模块添加一个具有新价格匹配的产品,然后再次添加相同的产品而没有价格匹配,在同一产品线中,它的数量增加但以前的价格值被替换为价格。所以我需要在添加产品期间由我的自定义模块手动更新最后的产品价格(当前模块如何做),但是当我退出当前订单时必须删除 priceHistory。任何人都可以提出解决这个问题的任何建议吗?非常感谢
我忘记了,在我发布的代码之后的原始文件中,还有这个代码部分:
'''
class SaleOrderLine(models.Model):
"""Inherit Sale Order Line."""
_inherit = "sale.order.line"
barcode = fields.Char(string='Barcode')
'''
也许可以影响一些东西?
解决方案
添加税收用途:
'tax_id' : [(4, account.tax.id)]
要获取当前订单的价格历史记录,请将order.id
as 键添加到priceHistory
.
priceHistory = {'order_id1': {'product_id1': ..., 'product_id2': ...}, ...}
看一下表格,该表格会在标准价格发生变化时product_price_history
对其进行跟踪。product.template
推荐阅读
- javascript - 如何将 django 模板中使用的 vue js 代码混淆为内联脚本?
- python - ' UnboundLocalError: 赋值前引用的局部变量 'command' '
- mysql - 在 TypeORM (MySQL) 中按名称、描述、标签等搜索项目的最佳方法是什么?
- c# - 如何从元数据类中正确确定实体框架中的关系?
- javascript - 我们如何将数字问题从 html 表单添加到 php 数据库
- python - Kivy 向 ScrollView 添加文本
- c++ - ESP8266[NodeMCU] LittleFS 库问题
- awk - 带有方括号的可变模式的 awk
- python - 针对捕获的 URI REF 打印更广泛和更窄的概念
- swift - SwiftUI:NSViewControllerRepresentable 中的 NSPageController 崩溃