简体   繁体   English

Odoo 自定义模块修复税收订单行?

[英]Odoo custom module fix taxes order line?

I'm a Odoo user (not developer).我是 Odoo 用户(不是开发人员)。 I have a custom module that have 2 bugs, I'm trying to understand how fix bugs, but I don't find solution.我有一个有 2 个错误的自定义模块,我试图了解如何修复错误,但我没有找到解决方案。 I think code interested is in model file.我认为感兴趣的代码是模型文件。 Module, by barcode scanning in a custom field, add product line in Order with Product, Description, Qty, Unit price, but missing taxes.模块,通过在自定义字段中扫描条形码,在订单中添加产品线,其中包含产品、描述、数量、单价,但缺少税金。 If same product barcode is scanned more time, is increase quantity in same product line.如果相同产品条码被扫描更多次,则增加相同产品线的数量。 First Bug issue is Not add Taxes, I have a product line without taxes.第一个错误问题是不加税,我有一条不含税的产品线。 I've seen inside code, and there is not any command that invokes Taxes.我已经看到内部代码,并且没有任何调用税收的命令。 Second bug issue is hold Price.第二个错误问题是保持价格。 The module allow to add and update price manually by custom field barcode scanning, and inside code there is command for hold last Price value update.该模块允许通过自定义字段条形码扫描手动添加和更新价格,并且在代码内部有保持最后价格值更新的命令。 Without this, if product is scanned again, come back to odoo price.如果没有这个,如果再次扫描产品,回到 odoo 价格。 Problems is the hold price value is not unlocked when I go out current order, So If I will create new order or update existent order, using custom module is applied Price value retained in previous order, and not odoo product price.问题是当我出去当前订单时,保持价格值没有解锁,所以如果我要创建新订单或更新现有订单,使用自定义模块会应用先前订单中保留的价格值,而不是 odoo 产品价格。

------------First code part: ------------第一部分代码:

# 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

Here I've tried to add:在这里,我尝试添加:

  'tax_id' : account.tax

belowe line线下

'price_unit': float(price) or product.list_price,

but not work.但不工作。

------------ Last code part ------------ 最后的代码部分

            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

Here, if I delete:在这里,如果我删除:

#save the product price
priceHistory[product_id.id] = price

I can solve Price value retained issue but I create a new issue: If module add a product with a new price matched, and subsequently add same product again Without price matched, in same product line it's increase quantity but previous Price value, is replaced by odoo price.我可以解决价格值保留问题,但我创建了一个新问题:如果模块添加了一个新价格匹配的产品,然后再次添加相同的产品没有价格匹配,在同一产品线中,它增加了数量但以前的价格值,被替换为奥多价格。 So I need to hold last product price updated manually by my custom module during adding products (how currently module do), but priceHistory must be erase when I go out current Order.因此,我需要在添加产品期间保留由我的自定义模块手动更新的最后产品价格(当前模块如何操作),但是当我退出当前订单时必须清除 priceHistory。 Can anyone give any suggestion for solve this issues?任何人都可以提出任何建议来解决这个问题吗? Thank you very much非常感谢

I've forgot, in original file after code which i've posted, there is also this code part:我忘记了,在我发布的代码之后的原始文件中,还有这个代码部分:

'''
class SaleOrderLine(models.Model):
    """Inherit Sale Order Line."""

    _inherit = "sale.order.line"

    barcode = fields.Char(string='Barcode')
'''

Maybe can influence something?也许可以影响一些东西?

To add tax use:添加税收用途:

'tax_id' : [(4, account.tax.id)]

To get price history in the current order, add order.id as key to priceHistory .要获取历史价格在目前的顺序,添加order.id作为关键priceHistory

priceHistory = {'order_id1': {'product_id1': ..., 'product_id2': ...}, ...}

Take a look at product_price_history table which keeps a track of the product.template standard prices as they are changed.看一下product_price_history表,它跟踪product.template标准价格的变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM