### Usage Example for _get_price Source: https://context7.com/oca/product-attribute/llms.txt Demonstrates how to call the `_get_price` method with various parameters like quantity, pricelist, and fiscal position to retrieve detailed pricing information for a product. ```python product = env['product.product'].browse(product_id) pricelist = env['product.pricelist'].browse(pricelist_id) fiscal_position = env['account.fiscal.position'].browse(fposition_id) price_info = product._get_price( qty=10.0, pricelist=pricelist, fposition=fiscal_position, company=env.company, date=fields.Date.today(), ) ``` -------------------------------- ### Create Product with Dimensions Source: https://context7.com/oca/product-attribute/llms.txt Example of creating a product template instance with dimensional attributes. The volume is automatically computed based on the provided dimensions and UoM. ```python product = env['product.template'].create({ 'name': 'Storage Box Large', 'dimensional_uom_id': env.ref('uom.product_uom_cm').id, 'product_length': 60.0, 'product_height': 40.0, 'product_width': 30.0, # Volume computed automatically: 0.072 m³ }) ``` -------------------------------- ### Calculate Packaging Breakdown Source: https://github.com/oca/product-attribute/blob/18.0/product_packaging_calculator/readme/USAGE.md Use this function to get a breakdown of how a total quantity can be represented by different packaging types. This is useful for warehouse operations. ```python >>> product.product_qty_by_packaging(2860) [ {"id": 1, "qty": 2, "name": "Pallet"}, {"id": 2, "qty": 1, "name": "Big box"}, {"id": 3, "qty": 7, "name": "Box"}, {"id": 100, "qty": 10, "name": "Units"}, ] ``` -------------------------------- ### Create and Use Product Profiles Source: https://context7.com/oca/product-attribute/llms.txt Demonstrates creating a product profile and then creating a product that utilizes this profile for automatic field configuration. ```python # Creating and using profiles consumable_profile = env['product.profile'].create({ 'name': 'Standard Consumable', 'explanation': 'Basic consumable product with standard settings', 'type': 'consu', # Additional fields defined by extending the profile model }) # Creating product with profile product = env['product.template'].create({ 'name': 'New Product', 'profile_id': consumable_profile.id, # All profile-controlled fields are automatically set }) ``` -------------------------------- ### Create Product with Manufacturer Details Source: https://context7.com/oca/product-attribute/llms.txt Demonstrates how to create a new product template and associate it with manufacturer information by searching for the manufacturer partner and setting the relevant fields. ```python # Setting manufacturer info manufacturer = env['res.partner'].search([('name', '=', 'Acme Manufacturing')], limit=1) product = env['product.template'].create({ 'name': 'Widget Pro', 'manufacturer_id': manufacturer.id, 'manufacturer_pname': 'Widget Professional Series', 'manufacturer_pref': 'WGT-PRO-2024', 'manufacturer_purl': 'https://acme.com/products/widget-pro', }) ``` -------------------------------- ### Define ABC Classification Profile Model Source: https://context7.com/oca/product-attribute/llms.txt Defines the data model for ABC classification profiles, including levels, type, period, and associated products. The 'profile_type' selection depends on installed modules. ```python class AbcClassificationProfile(models.Model): _name = "abc.classification.profile" _description = "Abc Classification Profile" name = fields.Char(required=True) level_ids = fields.One2many( comodel_name="abc.classification.level", inverse_name="profile_id" ) profile_type = fields.Selection(selection=[], required=True) period = fields.Integer(default=365, string="Period (Days)") product_variant_ids = fields.Many2many(comodel_name="product.product") auto_apply_computed_value = fields.Boolean(default=False) @api.constrains("level_ids") def _check_levels(self): for profile in self: percentages = profile.level_ids.mapped("percentage") if profile.level_ids and sum(percentages) != 100.0: raise ValidationError("Sum of percentages must be 100.") ``` -------------------------------- ### Set Up Multiple Prices for a Product Variant Source: https://context7.com/oca/product-attribute/llms.txt Associates specific prices (e.g., wholesale, retail) with a product variant. Ensure 'product.multi.price.name' records exist for the price names. ```python product = env['product.template'].browse(product_id) wholesale_price_name = env['product.multi.price.name'].create({'name': 'Wholesale'}) retail_price_name = env['product.multi.price.name'].create({'name': 'Retail'}) # Add prices to product variant product_variant = product.product_variant_ids[0] env['product.multi.price'].create({ 'product_id': product_variant.id, 'name': wholesale_price_name.id, 'price': 45.00, }) env['product.multi.price'].create({ 'product_id': product_variant.id, 'name': retail_price_name.id, 'price': 79.99, }) ``` -------------------------------- ### Extend Product Profile Model with Custom Fields Source: https://github.com/oca/product-attribute/blob/18.0/product_profile/README.rst Inherit the 'product.profile' model to add custom fields for product templates. Ensure these fields mirror original fields, especially the 'required' attribute. This example adds fields for sale, purchase, and POS availability. ```python class ProductProfile(models.Model): """ Require dependency on sale, purchase and point_of_sale modules """ _inherit = "product.profile" def _get_types(self): return [("product", "Stockable Product"), ("consu", 'Consumable'), ("service", "Service")] sale_ok = fields.Boolean( string="Can be Sold", help="Specify if the product can be selected in a sales order line.") purchase_ok = fields.Boolean( string="Can be Purchased") available_in_pos = fields.Boolean() ``` -------------------------------- ### Configure Category-Specific Product Sequence Source: https://context7.com/oca/product-attribute/llms.txt Sets up a dedicated sequence for products within a specific category, including prefix and padding for the reference code. ```python # Configure category-specific sequence category = env['product.category'].browse(category_id) category.product_sequence_id = env['ir.sequence'].create({ 'name': 'Electronics Product Sequence', 'code': 'product.product.electronics', 'prefix': 'ELEC-', 'padding': 5, }) ``` -------------------------------- ### Create Product with Auto-Sequence Source: https://context7.com/oca/product-attribute/llms.txt Creates a new product within a configured category, automatically assigning a sequence-based default code. ```python # Creating products - sequence assigned automatically product = env['product.product'].create({ 'name': 'New Electronic Device', 'categ_id': category.id, # default_code will be automatically set to 'ELEC-00001' }) ``` -------------------------------- ### Create Product Packaging Source: https://context7.com/oca/product-attribute/llms.txt Creates different levels of product packaging (unit, box, pallet) with specified quantities and packaging levels. ```python product = env['product.product'].browse(product_id) unit_pkg = env['product.packaging'].create({ 'name': 'Unit', 'product_id': product.id, 'qty': 1, 'packaging_level_id': primary_level.id, }) box_pkg = env['product.packaging'].create({ 'name': 'Box of 24', 'product_id': product.id, 'qty': 24, 'packaging_level_id': secondary_level.id, }) pallet_pkg = env['product.packaging'].create({ 'name': 'Pallet (48 boxes)', 'product_id': product.id, 'qty': 1152, # 48 * 24 'packaging_level_id': tertiary_level.id, }) ``` -------------------------------- ### Define Customer Product Information Source: https://context7.com/oca/product-attribute/llms.txt The `product.customerinfo` model, inheriting from `product.supplierinfo`, allows defining customer-specific product details such as names, codes, pricing, and validity periods. ```python class ProductCustomerInfo(models.Model): _inherit = "product.supplierinfo" _name = "product.customerinfo" _description = "Customer Pricelist" partner_id = fields.Many2one(string="Customer") product_name = fields.Char(string="Customer Product Name") product_code = fields.Char(string="Customer Product Code") min_qty = fields.Float(help="Minimum quantity for this price") price = fields.Float(help="Price at which product is sold to customer") date_start = fields.Date() date_end = fields.Date() ``` -------------------------------- ### Create Customer-Specific Product Info Source: https://context7.com/oca/product-attribute/llms.txt Use this snippet to create custom information entries for a product associated with a specific customer. Ensure the product and customer IDs are valid. ```python product = env['product.template'].browse(product_id) customer_info = env['product.customerinfo'].create({ 'partner_id': customer.id, 'product_tmpl_id': product.id, 'product_name': 'Custom Widget ABC', 'product_code': 'CUST-WGT-001', 'min_qty': 100, 'price': 25.50, 'date_start': '2024-01-01', 'date_end': '2024-12-31', }) ```