odoo 14 enterprise,
checking with automated action, with model product_template,
even the standard price is already input greater than 0.0, but error still showing up
if record.standard_price == 0:
raise UserError("Please update, product cost must be greater than 0.0")
I think it confuse between product.product and product.template
the purpose is to enforcing user to input for cost (standard_price)
any advice?
thanks in advance
try both model product.template and product.variant with trigger cost, but while editing product pop up window in quotation form, this always raise product error "Please update, product cost must be greater than 0.0", even cost have been update greater than 0
pls check screenshot below:
https://drive.google.com/file/d/1Ov0RWo_XyK-OdSS9qyjFT6dsQUBPds13/view?usp=sharing
https://drive.google.com/file/d/1OwzypGxaVwUTDoezPOqtniR-L60HXTAA/view?usp=sharing
raise UserError('Please update, product cost must be greater than 0.0')
The above line code should be 4 space indent.
create two automatic actions for product.product and product.template and use the below python and add cost field to target fields:
Please copy the code from my below answer, it's already formatted.
I have tried both options, but none is work, below for screen recording, for both automation actions
https://drive.google.com/file/d/139WhsGkJ-XGwjzcLR_Sll51j59gn4C7W/view?usp=sharing
also try with empty database also experience same problem
https://drive.google.com/file/d/13CSQ4AJiivqzOkc3d_aqPgaYW6MoOk7S/view?usp=sharing
It will work with you product without variant because the standard_price in product.template is computed field.
standard_price = fields.Float(
'Cost', compute='_compute_standard_price',
inverse='_set_standard_price', search='_search_standard_price',
digits='Product Price', groups="base.group_user",
help="""In Standard Price & AVCO: value of the product (automatically computed in AVCO).
In FIFO: value of the last unit that left the stock (automatically computed).
Used to value the product when the purchase cost is not known (e.g. inventory adjustment).
Used to compute margins on sale orders.""")
and the compute method set the standard price to zero and that's raise the error see the below compute method for standard_price field:
@api.depends_context('company')
@api.depends('product_variant_ids', 'product_variant_ids.standard_price')
def _compute_standard_price(self):
# Depends on force_company context because standard_price is company_dependent
# on the product_product
unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.standard_price = template.product_variant_ids.standard_price
for template in (self - unique_variants):
template.standard_price = 0.0
just enable only for automatic action on model product,
it works in product variant (model: product.template that use from add product in SO and PO), for it works as expected.
but for the product, cannot save even cost have change greater than 0