Odoo9安装product_print_zpl_barcode模块打印条码报AttributeError求助
Hey there, let's get that barcode printing module working again! The error you're hitting is a straightforward method name mismatch—Odoo 9's product.pricelist model doesn't have a get_product_pricelist() method, but it does have the correct built-in method to fetch product prices from a pricelist.
Root Cause
In your _compute_price method, you're calling a non-existent method wiz.pricelist_id.get_product_pricelist(). The correct method name for Odoo 9 is get_product_price(), and it expects specific parameters that align with the version's API. Additionally, the final return wiz.price line in the method is unnecessary (and incorrect for multi-record operations) since @api.depends methods automatically update field values without needing a return.
Fixed Code for _compute_price
Replace your existing _compute_price method with this corrected version:
@api.depends('pricelist_id', 'quantity', 'product_id') def _compute_price(self): # for regular barcodes for wiz in self: if wiz.pricelist_id and wiz.product_id: # Use Odoo 9's standard pricelist price retrieval method price_uom = wiz.pricelist_id.get_product_price( wiz.product_id, 1.0, partner_id=False, uom_id=wiz.uom_id.id ) wiz.price_uom = price_uom wiz.price = price_uom * wiz.quantity
Key Changes Explained
- Method Name Fix: Swapped
get_product_pricelist()withget_product_price()—this is the official method in Odoo 9 for getting a product's price from a pricelist. - Parameter Alignment: Added
uom_id=wiz.uom_id.idto ensure the price is calculated using the product's default unit of measure, which matches your module's logic. - Removed Unnecessary Return: The
return wiz.priceline was removed because@api.dependsmethods don't need to return values; they directly update the field values of each record inself.
Quick Additional Check
Double-check that your Odoo 9 instance has the core product module installed (which it should be, since you're working with product variants) and that the pricelist you're using has valid price rules configured for your products.
内容的提问来源于stack exchange,提问作者Dhouha

