Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

We have a server action to check the price on our EDI orders. If the order price and the system price don't match then it goes to an exception status to resolve.


We have just added some product category computed prices (e.g. all products 5% discount) however the rule that we have does not seem to work for computed prices and so every order is going to exception.

Can someone please look at the following and suggest changes that will allow for this rule to work on computed prices.


# Available variables:

#  - env: Odoo Environment on which the action is triggered

#  - model: Odoo Model of the record on which the action is triggered; is a void recordset

#  - record: record on which the action is triggered; may be void

#  - records: recordset of all records on which the action is triggered in multi-mode; may be void

#  - time, datetime, dateutil, timezone: useful Python libraries

#  - float_compare: Odoo function to compare floats based on specific precisions

#  - log: log(message, level='info'): logging function to record debug information in ir.logging table

#  - UserError: Warning Exception to use with raise

#  - Command: x2Many commands namespace

# To return an action, assign: action = {...}

create_vals = env.context.get("create_vals")

product_id = env["product.product"].search(

    ["|", ("id", "=", create_vals["product_id"]), ("product_tmpl_id", "=", create_vals["product_id"])])

uom = product_id.uom_id

quantity = create_vals["product_uom_qty"]

sale_order_id = env.context["order"]

pricelist_item_id = sale_order_id.partner_id.property_product_pricelist._get_product_rule(

    product_id, quantity)

date = sale_order_id.date_order

# price_without_tax = round(

#     env["product.pricelist.item"]

#     .browse(pricelist_item_id)

#     ._compute_base_price(

#         product_id, quantity, uom, date, product_id.currency_id

#     ),

#     2,

# )

price = 0.00

if pricelist_item_id:

  price = env["product.pricelist.item"].browse(pricelist_item_id).fixed_price

else:

  price = product_id.list_price

price_unit = create_vals["price_unit"]

if float_compare(price_unit, price, 2):

    msg = "Product Price (%s) is not equal to the price (%s) in XML for the Product (%s)." % (

        price, price_unit, product_id.name)

    raise UserError(msg)

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
2
Sep 24
6018
2
Jul 25
605
2
Jun 25
6675
0
Sep 24
1391
0
Mei 24
26