size
int64 0
304k
| ext
stringclasses 1
value | lang
stringclasses 1
value | branch
stringclasses 1
value | content
stringlengths 0
304k
| avg_line_length
float64 0
238
| max_line_length
int64 0
304k
|
|---|---|---|---|---|---|---|
2,889
|
py
|
PYTHON
|
15.0
|
# Copyright 2022 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ABCClassificationProfile(models.Model):
_inherit = "abc.classification.profile"
data_source = fields.Selection(
selection_add=[("sale_report", "Sales Report")],
ondelete={"sale_report": "set default"},
)
value_criteria = fields.Selection(
selection_add=[("sold_delivered_value", "Sold Delivered Value")],
ondelete={"sold_delivered_value": "set default"},
)
def _fill_initial_product_data(self, date, date_end=False):
if self.data_source == "sale_report":
return self._fill_data_from_sale_report(date, [], date_end=date_end)
return super()._fill_initial_product_data(date, date_end=date_end)
def _fill_data_from_sale_report(self, date, product_list, date_end=False):
domain = [
("state", "in", ["sale", "done"]),
("date", ">=", date),
("qty_delivered", ">", 0),
"|",
("product_id.abc_classification_profile_id", "=", self.id),
"|",
("product_id.categ_id.abc_classification_profile_id", "=", self.id),
(
"product_id.categ_id.parent_id.abc_classification_profile_id",
"=",
self.id,
),
]
if date_end:
domain.append(("date", "<=", date_end))
sales_report = self.env["sale.report"].read_group(
domain,
["product_id", "price_subtotal", "product_uom_qty", "qty_delivered"],
["product_id"],
)
for result in sales_report:
product_uom_qty = result["product_uom_qty"]
product_data = {
"product": self.env["product.product"].browse(result["product_id"][0]),
"units_sold": product_uom_qty,
"price_subtotal_delivered": product_uom_qty
and (result.get("price_subtotal") / result.get("product_uom_qty"))
* result.get("qty_delivered")
or 0,
}
product_list.append(product_data)
return product_list
def _fill_data_from_stock_moves(self, date, product_list, date_end=False):
product_list = super()._fill_data_from_stock_moves(
date, product_list, date_end=False
)
for product_data in product_list:
product_data["price_subtotal_delivered"] = (
product_data["product"].list_price * product_data["units_sold"]
)
return product_list
def _get_inventory_product_value(self, data):
self.ensure_one()
if self.value_criteria == "sold_delivered_value":
return data["price_subtotal_delivered"]
return super()._get_inventory_product_value(data)
| 39.575342
| 2,889
|
628
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Product Pricelist Print Website Sale",
"summary": "Extend Product Pricelist Direct Print for filter by public"
" categories",
"version": "15.0.1.0.0",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"maintainers": ["CarlosRoca13"],
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["product_pricelist_direct_print", "website_sale"],
"data": ["wizards/product_pricelist_print_view.xml"],
}
| 41.866667
| 628
|
956
|
py
|
PYTHON
|
15.0
|
# Copyright 2022 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, models
class ProductPricelistXlsx(models.AbstractModel):
_inherit = "report.product_pricelist_direct_print.product_pricelist_xlsx"
def _add_extra_header(self, sheet, book, next_col, header_format):
next_col = super()._add_extra_header(sheet, book, next_col, header_format)
if book.show_public_category:
next_col += 1
sheet.write(5, next_col, _("Public Category"), header_format)
return next_col
def _add_extra_info(self, sheet, book, product, row, next_col, **kw):
next_col = super()._add_extra_info(sheet, book, product, row, next_col, **kw)
if book.show_public_category:
next_col += 1
if product.public_categ_ids:
sheet.write(row, next_col, product.public_categ_ids[:1].display_name)
return next_col
| 43.454545
| 956
|
992
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ProductPricelistPrint(models.TransientModel):
_inherit = "product.pricelist.print"
is_public_categ = fields.Boolean(string="Filter/Group by public categories")
show_public_category = fields.Boolean(string="Show public categories")
public_categ_ids = fields.Many2many(
"product.public.category", string="Website Product Category"
)
def get_products_domain(self):
domain = super().get_products_domain()
if self.public_categ_ids:
domain.append(("public_categ_ids", "in", self.public_categ_ids.ids))
return domain
def get_group_key(self, product):
if self.is_public_categ:
if product.public_categ_ids:
return product.public_categ_ids[:1].name
else:
return ""
return super().get_group_key(product)
| 35.428571
| 992
|
633
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 brain-tec AG (http://www.braintec-group.com)
# Copyright 2015-2016 Camptocamp SA
# Copyright 2015 ADHOC SA (http://www.adhoc.com.ar)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Product Dimension",
"version": "15.0.1.0.1",
"category": "Product",
"author": "brain-tec AG, ADHOC SA, Camptocamp SA, "
"Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/product-attribute",
"depends": ["product"],
"data": ["views/product_view.xml"],
"installable": True,
"images": ["static/description/icon.png"],
}
| 37.235294
| 633
|
2,159
|
py
|
PYTHON
|
15.0
|
# Copyright 2015 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestComputeVolumeOnProduct(TransactionCase):
def test_it_computes_volume_in_cm(self):
self.product.product_length = 10.0
self.product.product_height = 200.0
self.product.product_width = 100.0
self.product.dimensional_uom_id = self.uom_cm
self.product.onchange_calculate_volume()
self.assertAlmostEqual(0.2, self.product.volume)
def test_it_computes_volume_in_meters(self):
self.product.product_length = 6.0
self.product.product_height = 2.0
self.product.product_width = 10.0
self.product.dimensional_uom_id = self.uom_m
self.product.onchange_calculate_volume()
self.assertAlmostEqual(120, self.product.volume)
def setUp(self):
super(TestComputeVolumeOnProduct, self).setUp()
self.product = self.env["product.product"].new()
self.uom_m = self.env["uom.uom"].search([("name", "=", "m")])
self.uom_cm = self.env["uom.uom"].search([("name", "=", "cm")])
class TestComputeVolumeOnTemplate(TransactionCase):
def test_it_computes_volume_in_cm(self):
self.template.product_length = 10.0
self.template.product_height = 200.0
self.template.product_width = 100.0
self.template.dimensional_uom_id = self.uom_cm
self.template.onchange_calculate_volume()
self.assertAlmostEqual(0.2, self.template.volume)
def test_it_computes_volume_in_meters(self):
self.template.product_length = 6.0
self.template.product_height = 2.0
self.template.product_width = 10.0
self.template.dimensional_uom_id = self.uom_m
self.template.onchange_calculate_volume()
self.assertAlmostEqual(120, self.template.volume)
def setUp(self):
super(TestComputeVolumeOnTemplate, self).setUp()
self.template = self.env["product.template"].new()
self.uom_m = self.env["uom.uom"].search([("name", "=", "m")])
self.uom_cm = self.env["uom.uom"].search([("name", "=", "cm")])
| 40.735849
| 2,159
|
2,026
|
py
|
PYTHON
|
15.0
|
# Copyright 2015 ADHOC SA (http://www.adhoc.com.ar)
# Copyright 2015-2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
# Define all the related fields in product.template with 'readonly=False'
# to be able to modify the values from product.template.
dimensional_uom_id = fields.Many2one(
"uom.uom",
"Dimensional UoM",
related="product_variant_ids.dimensional_uom_id",
help="UoM for length, height, width",
readonly=False,
)
product_length = fields.Float(
related="product_variant_ids.product_length", readonly=False
)
product_height = fields.Float(
related="product_variant_ids.product_height", readonly=False
)
product_width = fields.Float(
related="product_variant_ids.product_width", readonly=False
)
@api.model
def _calc_volume(self, product_length, product_height, product_width, uom_id):
volume = 0
if product_length and product_height and product_width and uom_id:
length_m = self.convert_to_meters(product_length, uom_id)
height_m = self.convert_to_meters(product_height, uom_id)
width_m = self.convert_to_meters(product_width, uom_id)
volume = length_m * height_m * width_m
return volume
@api.onchange(
"product_length", "product_height", "product_width", "dimensional_uom_id"
)
def onchange_calculate_volume(self):
self.volume = self._calc_volume(
self.product_length,
self.product_height,
self.product_width,
self.dimensional_uom_id,
)
def convert_to_meters(self, measure, dimensional_uom):
uom_meters = self.env.ref("uom.product_uom_meter")
return dimensional_uom._compute_quantity(
qty=measure,
to_unit=uom_meters,
round=False,
)
| 34.338983
| 2,026
|
1,158
|
py
|
PYTHON
|
15.0
|
# Copyright 2015 ADHOC SA (http://www.adhoc.com.ar)
# Copyright 2015-2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductProduct(models.Model):
_inherit = "product.product"
product_length = fields.Float("length")
product_height = fields.Float("height")
product_width = fields.Float("width")
dimensional_uom_id = fields.Many2one(
"uom.uom",
"Dimensional UoM",
domain=lambda self: self._get_dimension_uom_domain(),
help="UoM for length, height, width",
default=lambda self: self.env.ref("uom.product_uom_meter"),
)
@api.onchange(
"product_length", "product_height", "product_width", "dimensional_uom_id"
)
def onchange_calculate_volume(self):
self.volume = self.env["product.template"]._calc_volume(
self.product_length,
self.product_height,
self.product_width,
self.dimensional_uom_id,
)
@api.model
def _get_dimension_uom_domain(self):
return [("category_id", "=", self.env.ref("uom.uom_categ_length").id)]
| 33.085714
| 1,158
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
3,290
|
py
|
PYTHON
|
15.0
|
import setuptools
with open('VERSION.txt', 'r') as f:
version = f.read().strip()
setuptools.setup(
name="odoo-addons-oca-product-attribute",
description="Meta package for oca-product-attribute Odoo addons",
version=version,
install_requires=[
'odoo-addon-base_product_mass_addition>=15.0dev,<15.1dev',
'odoo-addon-product_abc_classification>=15.0dev,<15.1dev',
'odoo-addon-product_abc_classification_sale>=15.0dev,<15.1dev',
'odoo-addon-product_assortment>=15.0dev,<15.1dev',
'odoo-addon-product_attribute_archive>=15.0dev,<15.1dev',
'odoo-addon-product_attribute_value_menu>=15.0dev,<15.1dev',
'odoo-addon-product_category_active>=15.0dev,<15.1dev',
'odoo-addon-product_category_code>=15.0dev,<15.1dev',
'odoo-addon-product_category_code_unique>=15.0dev,<15.1dev',
'odoo-addon-product_category_product_link>=15.0dev,<15.1dev',
'odoo-addon-product_code_mandatory>=15.0dev,<15.1dev',
'odoo-addon-product_code_unique>=15.0dev,<15.1dev',
'odoo-addon-product_cost_security>=15.0dev,<15.1dev',
'odoo-addon-product_dimension>=15.0dev,<15.1dev',
'odoo-addon-product_drained_weight>=15.0dev,<15.1dev',
'odoo-addon-product_logistics_uom>=15.0dev,<15.1dev',
'odoo-addon-product_lot_sequence>=15.0dev,<15.1dev',
'odoo-addon-product_manufacturer>=15.0dev,<15.1dev',
'odoo-addon-product_multi_image>=15.0dev,<15.1dev',
'odoo-addon-product_multi_price>=15.0dev,<15.1dev',
'odoo-addon-product_net_weight>=15.0dev,<15.1dev',
'odoo-addon-product_order_noname>=15.0dev,<15.1dev',
'odoo-addon-product_packaging_type>=15.0dev,<15.1dev',
'odoo-addon-product_pricelist_by_contact>=15.0dev,<15.1dev',
'odoo-addon-product_pricelist_direct_print>=15.0dev,<15.1dev',
'odoo-addon-product_pricelist_direct_print_company_group>=15.0dev,<15.1dev',
'odoo-addon-product_pricelist_direct_print_website_sale>=15.0dev,<15.1dev',
'odoo-addon-product_pricelist_revision>=15.0dev,<15.1dev',
'odoo-addon-product_pricelist_simulation>=15.0dev,<15.1dev',
'odoo-addon-product_pricelist_supplierinfo>=15.0dev,<15.1dev',
'odoo-addon-product_profile>=15.0dev,<15.1dev',
'odoo-addon-product_restricted_type>=15.0dev,<15.1dev',
'odoo-addon-product_secondary_unit>=15.0dev,<15.1dev',
'odoo-addon-product_sequence>=15.0dev,<15.1dev',
'odoo-addon-product_state>=15.0dev,<15.1dev',
'odoo-addon-product_sticker>=15.0dev,<15.1dev',
'odoo-addon-product_supplierinfo_archive>=15.0dev,<15.1dev',
'odoo-addon-product_supplierinfo_for_customer>=15.0dev,<15.1dev',
'odoo-addon-product_supplierinfo_revision>=15.0dev,<15.1dev',
'odoo-addon-product_template_tags>=15.0dev,<15.1dev',
'odoo-addon-product_variant_attribute_name_manager>=15.0dev,<15.1dev',
'odoo-addon-purchase_product_template_tags>=15.0dev,<15.1dev',
'odoo-addon-sale_product_template_tags>=15.0dev,<15.1dev',
'odoo-addon-stock_product_template_tags>=15.0dev,<15.1dev',
],
classifiers=[
'Programming Language :: Python',
'Framework :: Odoo',
'Framework :: Odoo :: 15.0',
]
)
| 53.934426
| 3,290
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
100
|
py
|
PYTHON
|
15.0
|
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
| 16.666667
| 100
|
730
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Product Pricelist Simulation",
"summary": "Simulate the product price for all pricelists",
"version": "15.0.1.0.0",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"author": "GRAP, Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["product"],
"data": [
"security/ir.model.access.csv",
"wizards/wizard_preview_pricelist_views.xml",
"views/product_views.xml",
"views/pricelist_views.xml",
],
}
| 33.181818
| 730
|
4,112
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 Tecnativa - Sergio Teruel
# Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests import Form, common
class TestProductPricelistSimulation(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.template_1 = cls.env["product.template"].create(
{"name": "Template 1", "list_price": 100.00}
)
attr = cls.env["product.attribute"].create({"name": "Attr"})
attr_value_1 = cls.env["product.attribute.value"].create(
{"name": "Value 1", "attribute_id": attr.id},
)
attr_value_2 = cls.env["product.attribute.value"].create(
{"name": "Value 2", "attribute_id": attr.id},
)
cls.template_2 = cls.env["product.template"].create(
{
"name": "Template 2",
"list_price": 1000.00,
"attribute_line_ids": [
(
0,
0,
{
"attribute_id": attr.id,
"value_ids": [(6, 0, [attr_value_1.id, attr_value_2.id])],
},
)
],
}
)
# uncheck 'show_in_simulation' in existing pricelist (just in case)
cls.env["product.pricelist"].search([]).show_in_simulation = False
cls.pricelist_1 = cls.env["product.pricelist"].create(
{
"name": "Pricelist 1",
"currency_id": cls.env.company.currency_id.id,
"item_ids": [
(
0,
0,
{
"applied_on": "3_global",
"compute_price": "fixed",
"fixed_price": 80.00,
},
)
],
}
)
cls.pricelist_2 = cls.env["product.pricelist"].create(
{
"name": "Pricelist 2",
"currency_id": cls.env.company.currency_id.id,
"item_ids": [
(
0,
0,
{
"applied_on": "3_global",
"compute_price": "percentage",
"percent_price": 50.00,
},
)
],
}
)
cls.pricelist_3 = cls.env["product.pricelist"].create(
{
"name": "Pricelist3",
"currency_id": cls.env.company.currency_id.id,
"show_in_simulation": False,
}
)
def test_pricelist_simulation_product_template(self):
# # Template 1
wizard_form = Form(
self.env["wizard.preview.pricelist"].with_context(
active_model="product.template",
active_id=self.template_1.id,
),
)
self.assertAlmostEqual(wizard_form.line_ids._records[0]["price"], 50.0)
self.assertAlmostEqual(wizard_form.line_ids._records[1]["price"], 80.0)
# # Template 2
wizard_form = Form(
self.env["wizard.preview.pricelist"].with_context(
active_model="product.template",
active_id=self.template_2.id,
),
)
prices = [r["price"] for r in wizard_form.line_ids._records]
self.assertAlmostEqual(prices, [500.0, 80.0, 500.0, 80.0])
def test_pricelist_simulation_product_variant(self):
wizard_form = Form(
self.env["wizard.preview.pricelist"].with_context(
active_model="product.product",
active_id=self.template_1.product_variant_ids.id,
),
)
self.assertAlmostEqual(wizard_form.line_ids._records[0]["price"], 50.0)
self.assertAlmostEqual(wizard_form.line_ids._records[1]["price"], 80.0)
| 37.381818
| 4,112
|
300
|
py
|
PYTHON
|
15.0
|
# Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ProductPricelist(models.Model):
_inherit = "product.pricelist"
show_in_simulation = fields.Boolean(string="Show in simulation", default=True)
| 30
| 300
|
3,544
|
py
|
PYTHON
|
15.0
|
# Copyright 2022 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class PricelistSimulation(models.TransientModel):
_name = "wizard.preview.pricelist"
_description = "wizard - Preview Pricelist"
@api.model
def default_get(self, fields):
vals = super().default_get(fields)
if self.env.context.get("active_model") == "product.template":
vals["template_id"] = self.env.context.get("active_id")
else:
active_id = self.env.context.get("active_id")
product = self.env["product.product"].browse(active_id)
vals["product_id"] = product.id
vals["template_id"] = product.product_tmpl_id.id
return vals
template_id = fields.Many2one(
comodel_name="product.template", string="Product Template", readonly=True
)
product_id = fields.Many2one(
comodel_name="product.product",
domain="[('product_tmpl_id', '=', template_id)]",
string="Product Variant",
)
product_qty = fields.Float(string="Quantity", default=1, required=True)
price_date = fields.Datetime(
string="Date", default=fields.Date.context_today, required=True
)
line_ids = fields.One2many(
string="Simulation Lines",
comodel_name="wizard.preview.pricelist.line",
inverse_name="simulation_id",
compute="_compute_line_ids",
)
variant_count = fields.Integer(
string="Variants Count", compute="_compute_variant_count"
)
@api.depends("template_id", "product_id", "product_qty", "price_date")
def _compute_line_ids(self):
self.ensure_one()
pricelists = self.env["product.pricelist"].search(
[("show_in_simulation", "=", True)],
)
line_ids_vals = []
for variant in self.product_id or self.template_id.product_variant_ids:
for pricelist in pricelists:
vals = self._prepare_simulation_lines_vals(variant, pricelist)
line_ids_vals.append((0, False, vals))
self.line_ids = line_ids_vals
def _prepare_simulation_lines_vals(self, variant, pricelist):
price = variant.with_context(
pricelist=pricelist.id,
quantity=self.product_qty,
date=self.price_date,
).price
return {
"product_id": variant.id,
"pricelist_id": pricelist.id,
"price": price,
}
@api.depends("template_id")
def _compute_variant_count(self):
self.ensure_one()
self.variant_count = 1
if not self.product_id:
self.variant_count = len(self.template_id.product_variant_ids)
class PricelistSimulationLine(models.TransientModel):
_name = "wizard.preview.pricelist.line"
_description = "wizard - Preview Pricelist Line"
simulation_id = fields.Many2one(
string="Simulation",
comodel_name="wizard.preview.pricelist",
)
product_id = fields.Many2one(
comodel_name="product.product",
string="Product Variant",
readonly=True,
)
pricelist_id = fields.Many2one(
comodel_name="product.pricelist",
string="Pricelist",
readonly=True,
)
currency_id = fields.Many2one(
comodel_name="res.currency",
related="pricelist_id.currency_id",
string="Currency",
readonly=True,
)
price = fields.Monetary(readonly=True, currency_field="currency_id")
| 34.407767
| 3,544
|
739
|
py
|
PYTHON
|
15.0
|
# Copyright 2019-2020 Camptocamp (<https://www.camptocamp.com>).
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Product Packaging Type",
"version": "15.0.1.0.0",
"development_status": "Beta",
"category": "Product",
"summary": "Product Packaging Type",
"author": "Camptocamp, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"license": "LGPL-3",
"depends": ["product", "stock"],
"data": [
"data/product_packaging_type.xml",
"security/ir.model.access.csv",
"views/product_packaging_type_view.xml",
"views/product_packaging_view.xml",
],
"installable": True,
"auto_install": False,
}
| 33.590909
| 739
|
6,080
|
py
|
PYTHON
|
15.0
|
# Copyright 2019-2020 Camptocamp (<https://www.camptocamp.com>).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
from collections import OrderedDict
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ProductPackagingType(models.Model):
_name = "product.packaging.type"
_description = "Type management for product.packaging"
_order = "sequence, code"
name = fields.Char(required=True, translate=True)
code = fields.Char(required=True)
sequence = fields.Integer(required=True)
has_gtin = fields.Boolean()
active = fields.Boolean(default=True)
is_default = fields.Boolean()
@api.constrains("is_default")
def _check_is_default(self):
msg = False
default_count = self.search_count([("is_default", "=", True)])
if default_count == 0:
msg = _('There must be one product packaging type set as "Is Default".')
elif default_count > 1:
msg = _('Only one product packaging type can be set as "Is Default".')
if msg:
raise ValidationError(msg)
def name_get(self):
result = []
for record in self:
result.append((record.id, "{} ({})".format(record.name, record.code)))
return result
class ProductPackaging(models.Model):
_inherit = "product.packaging"
_order = "product_id, type_sequence"
def default_packaging_type_id(self):
return self.env["product.packaging.type"].search(
[("is_default", "=", True)], limit=1
)
packaging_type_id = fields.Many2one(
"product.packaging.type",
required=True,
ondelete="restrict",
default=lambda p: p.default_packaging_type_id(),
)
barcode_required_for_gtin = fields.Boolean(
readonly=True, compute="_compute_barcode_required_for_gtin"
)
type_sequence = fields.Integer(
string="Type sequence",
related="packaging_type_id.sequence",
readonly=True,
store=True,
)
qty_per_type = fields.Char(
compute="_compute_qty_per_type", string="Qty per package type"
)
@api.constrains("packaging_type_id", "product_id")
def _check_one_packaging_type_per_product(self):
for packaging in self:
product = packaging.product_id
# do not use a mapped/filtered because it would union the duplicates
packaging_type_ids = [
packaging.packaging_type_id.id
for packaging in product.packaging_ids
# We have to allow several packaging using the default type,
# because when we install the module on an existing database,
# the default value will be set to default and we'll have
# duplicates. Anyway "default" is not meant to be used as a
# real type.
if not packaging.packaging_type_id.is_default
]
if len(set(packaging_type_ids)) != len(packaging_type_ids):
raise ValidationError(
_(
"It is forbidden to have different packagings "
"with the same type for a given product ({})."
).format(product.display_name)
)
@api.depends("packaging_type_id", "packaging_type_id.has_gtin", "qty")
def _compute_barcode_required_for_gtin(self):
for packaging in self:
packaging.barcode_required_for_gtin = packaging.packaging_type_id.has_gtin
if not packaging.qty:
packaging.barcode_required_for_gtin = False
@api.depends(
"product_id",
"product_id.packaging_ids",
"packaging_type_id",
"packaging_type_id.code",
)
def _compute_qty_per_type(self):
for packaging in self:
if not packaging.product_id:
packaging.qty_per_type = ""
continue
mapping = packaging._get_qty_per_type_mapping()
packaging.qty_per_type = packaging._format_qty_per_type(mapping)
def _get_qty_per_type_mapping(self):
"""Retrieve qty for each packaging type.
:return: mapping {type.code: qty}
"""
smaller_product_packagings = self.product_id.packaging_ids.filtered(
lambda p: p.id != self.id and self.qty > p.qty > 0.0
)
res = OrderedDict()
for p_pack in smaller_product_packagings.sorted(lambda p: p.qty):
res[p_pack.packaging_type_id.code] = p_pack.qty
return res
def _format_qty_per_type(self, qty_per_type_mapping, format_pattern=None):
"""Format given qty per type mapping as string."""
qty_per_type = self._make_qty_per_type(
qty_per_type_mapping, format_pattern=format_pattern
)
res = []
for code, qty in qty_per_type:
res.append("{} {}".format(qty, code))
return "; ".join(res)
def _make_qty_per_type(self, qty_per_type_mapping, format_pattern=None):
"""Prepare list of packaging qty by code."""
res = []
format_pattern = format_pattern or "{}{}"
for code, qty in qty_per_type_mapping.items():
new_qty = self.qty / qty
if not new_qty.is_integer():
new_qty_int = int(new_qty)
new_qty_decimals = new_qty - new_qty_int
new_qty = format_pattern.format(
new_qty_int, str(new_qty_decimals).lstrip("0")
)
res.append((code, new_qty))
return res
@api.onchange("packaging_type_id")
def _onchange_name(self):
if self.packaging_type_id:
self.name = self.packaging_type_id.name
def name_get(self):
result = []
for record in self:
if record.product_id and record.packaging_type_id:
result.append((record.id, record.packaging_type_id.display_name))
else:
result.append((record.id, record.name))
return result
| 37.763975
| 6,080
|
665
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ACSONE SA/NV
# Copyright 2023 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Assortment",
"summary": """
Adds the ability to manage products assortment""",
"version": "15.0.2.0.0",
"license": "AGPL-3",
"development_status": "Production/Stable",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"depends": ["base", "product"],
"data": [
"data/ir_cron.xml",
"views/product_assortment.xml",
"views/res_partner_view.xml",
],
"installable": True,
}
| 31.666667
| 665
|
5,847
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from psycopg2 import IntegrityError
from odoo.tests.common import TransactionCase
from odoo.tools.misc import mute_logger
class TestProductAssortment(TransactionCase):
def setUp(self):
super(TestProductAssortment, self).setUp()
self.filter_obj = self.env["ir.filters"]
self.product_obj = self.env["product.product"]
self.assortment = self.filter_obj.create(
{
"name": "Test Assortment",
"model_id": "product.product",
"is_assortment": True,
"domain": [],
}
)
self.partner = self.env["res.partner"].create({"name": "Test partner"})
self.partner2 = self.env["res.partner"].create({"name": "Test partner 2"})
def test_assortment(self):
products = self.product_obj.search([])
domain = self.assortment._get_eval_domain()
products_filtered = self.product_obj.search(domain)
self.assertEqual(products.ids, products_filtered.ids)
# reduce assortment to services products
domain = [("type", "=", "service")]
self.assortment.domain = domain
products = self.product_obj.search(domain)
domain = self.assortment._get_eval_domain()
products_filtered = self.product_obj.search(domain)
self.assertEqual(products.ids, products_filtered.ids)
# include one product not in initial filter
included_product = self.env.ref("product.product_product_7")
self.assortment.write({"whitelist_product_ids": [(4, included_product.id)]})
domain = self.assortment._get_eval_domain()
products_filtered = self.product_obj.search(domain)
self.assertIn(included_product.id, products_filtered.ids)
# exclude one product not in initial filter
excluded_product = self.env.ref("product.product_product_2")
domain = self.assortment._get_eval_domain()
products_filtered = self.product_obj.search(domain)
self.assertIn(excluded_product.id, products_filtered.ids)
self.assortment.write({"blacklist_product_ids": [(4, excluded_product.id)]})
domain = self.assortment._get_eval_domain()
products_filtered = self.product_obj.search(domain)
self.assertNotIn(excluded_product.id, products_filtered.ids)
def test_assortment_not_available_search_view(self):
model = self.env.ref("product.model_product_product")
filters = self.filter_obj.get_filters(model.id)
self.assertFalse(filters)
def test_create_assortment_with_context(self):
assortment = self.filter_obj.with_context(product_assortment=True).create(
{"name": "Test Assortment Context", "domain": []}
)
self.assertTrue(assortment.is_assortment)
self.assertEqual(assortment.model_id, "product.product")
@mute_logger("odoo.sql_db")
def test_create_assortment_without_context(self):
with self.assertRaises(IntegrityError), self.env.cr.savepoint():
self.filter_obj.with_context(product_assortment=False).create(
{"name": "Test Assortment No Context", "domain": []}
)
def test_search_assortment_with_partner(self):
self.filter_obj.with_context(product_assortment=True).create(
{
"name": "Test Assortment Partner",
"domain": [],
"partner_ids": [(4, self.partner.id)],
}
)
search_domain = self.partner.action_define_product_assortment()["domain"]
self.assertEqual(
search_domain,
[("partner_ids", "in", [self.partner.id]), ("is_assortment", "=", True)],
)
def test_product_assortment_view(self):
included_product = self.env.ref("product.product_product_7")
self.assortment.write({"whitelist_product_ids": [(4, included_product.id)]})
res = self.assortment.show_products()
self.assertEqual(res["domain"], [("id", "in", [included_product.id])])
def test_record_count(self):
products = self.product_obj.search([])
self.assertEqual(self.assortment.record_count, len(products))
# reduce assortment to services products
domain = [("type", "=", "service")]
self.assortment.domain = domain
products = self.product_obj.search(domain)
domain = self.assortment._get_eval_domain()
products_filtered = self.product_obj.search(domain)
self.assortment.invalidate_cache()
self.assertEqual(self.assortment.record_count, len(products_filtered))
def test_assortment_with_partner_domain(self):
assortment = self.filter_obj.with_context(product_assortment=True).create(
{
"name": "Test Assortment Partner domain",
"partner_domain": "[('id', '=', %s)]" % self.partner.id,
"partner_ids": [(4, self.partner2.id)],
}
)
self.assertEqual(assortment.all_partner_ids, self.partner + self.partner2)
def test_assortment_with_black_list_product_domain(self):
excluded_product = self.env.ref("product.product_product_7")
assortment = self.filter_obj.with_context(product_assortment=True).create(
{
"name": "Test Assortment black product domain",
"domain": [],
"partner_ids": [(4, self.partner2.id)],
"apply_black_list_product_domain": True,
"black_list_product_domain": [("id", "=", excluded_product.id)],
}
)
allowed_products = self.env["product.product"].search(
assortment._get_eval_domain()
)
self.assertNotIn(excluded_product, allowed_products)
| 43.634328
| 5,847
|
6,398
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ACSONE SA/NV
# Copyright 2023 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.osv import expression
from odoo.tools import ormcache
from odoo.tools.safe_eval import datetime, safe_eval
class IrFilters(models.Model):
_inherit = "ir.filters"
@api.model
def _get_default_is_assortment(self):
if self.env.context.get("product_assortment", False):
return True
return False
@api.model
def _update_assortment_default_values(self, vals_list):
"""
If we create the filter through the assortment, we need to force
model_id to product.product
"""
product_assortment = self.env.context.get("product_assortment", False)
if not product_assortment:
return vals_list
model = self.env.ref("product.model_product_product")
for vals in vals_list:
if not vals.get("model_id"):
vals.update({"model_id": model.model})
return vals_list
@api.model_create_multi
def create(self, vals_list):
self._update_assortment_default_values(vals_list=vals_list)
return super().create(vals_list=vals_list)
partner_ids = fields.Many2many(
comodel_name="res.partner",
help="This field allow to relate a partner to a domain of products",
default=lambda p: p.env.context.get("default_partner_ids"),
)
blacklist_product_ids = fields.Many2many(
comodel_name="product.product",
string="Restricted products",
relation="assortment_product_blacklisted",
)
whitelist_product_ids = fields.Many2many(
comodel_name="product.product",
string="Allowed products",
relation="assortment_product_whitelisted",
)
record_count = fields.Integer(compute="_compute_record_count")
is_assortment = fields.Boolean(default=lambda x: x._get_default_is_assortment())
partner_domain = fields.Text(default="[]", required=True)
all_partner_ids = fields.Many2many(
comodel_name="res.partner",
compute="_compute_all_partner_ids",
# Make it store=True because we will need this field to search by involved
# partners
store=True,
relation="ir_filter_all_partner_rel",
column1="filter_id",
column2="partner_id",
)
apply_black_list_product_domain = fields.Boolean(
string="Apply restricted product domain"
)
black_list_product_domain = fields.Text(
string="Restricted product domain", default="[]", required=True
)
@api.model
@ormcache()
def get_partner_domain_fields(self):
field_set = set()
for ir_filter in self.sudo().search([("is_assortment", "=", True)]):
domain = ir_filter._get_eval_partner_domain()
for item in domain:
if isinstance(item, (list, tuple)) and isinstance(item[0], str):
field_set.add(item[0].split(".")[0])
return field_set
@api.depends("partner_ids", "partner_domain")
def _compute_all_partner_ids(self):
"""Summarize selected partners and partners from partner domain field"""
for ir_filter in self:
if not ir_filter.is_assortment:
ir_filter.all_partner_ids = False
elif ir_filter.partner_domain != "[]":
ir_filter.all_partner_ids = (
self.env["res.partner"].search(ir_filter._get_eval_partner_domain())
+ ir_filter.partner_ids
)
else:
ir_filter.all_partner_ids = ir_filter.partner_ids
def _get_eval_domain(self):
res = super()._get_eval_domain()
if self.apply_black_list_product_domain:
black_list_domain = safe_eval(
self.black_list_product_domain,
{"datetime": datetime, "context_today": datetime.datetime.now},
)
res = expression.AND(
[expression.distribute_not(["!"] + black_list_domain), res]
)
if self.whitelist_product_ids:
result_domain = [("id", "in", self.whitelist_product_ids.ids)]
res = expression.OR([result_domain, res])
if self.blacklist_product_ids:
result_domain = [("id", "not in", self.blacklist_product_ids.ids)]
res = expression.AND([result_domain, res])
return res
def _get_eval_black_list_domain(self):
res = safe_eval(
self.black_list_product_domain,
{"datetime": datetime, "context_today": datetime.datetime.now},
)
if self.blacklist_product_ids:
result_domain = [("id", "not in", self.blacklist_product_ids.ids)]
res = expression.AND([result_domain, res])
return res
def _get_eval_partner_domain(self):
self.ensure_one()
return safe_eval(
self.partner_domain,
{"datetime": datetime, "context_today": datetime.datetime.now},
)
def _compute_record_count(self):
for record in self:
if record.model_id not in self.env:
# invalid model
record.record_count = 0
continue
domain = record._get_eval_domain()
record.record_count = self.env[record.model_id].search_count(domain)
@api.model
def _get_action_domain(self, action_id=None):
# tricky way to act on get_filter method to prevent returning
# assortment in search view filters
domain = super()._get_action_domain(action_id=action_id)
domain = expression.AND([[("is_assortment", "=", False)], domain])
return domain
def write(self, vals):
res = super().write(vals)
if "partner_ids" in vals or "partner_domain" in vals:
self.clear_caches()
return res
def show_products(self):
self.ensure_one()
xmlid = "product.product_normal_action_sell"
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
action.update(
{
"domain": self._get_eval_domain(),
"name": _("Products"),
"context": self.env.context,
"target": "current",
}
)
return action
| 36.56
| 6,398
|
2,235
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 Tecnativa - Carlos Roca
# Copyright 2021 Tecnativa - Carlos Dauden
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
applied_assortment_ids = fields.Many2many(
comodel_name="ir.filters",
relation="ir_filter_all_partner_rel",
column1="partner_id",
column2="filter_id",
)
def action_define_product_assortment(self):
self.ensure_one()
xmlid = "product_assortment.actions_product_assortment_view"
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
action["domain"] = [
("partner_ids", "in", self.ids),
("is_assortment", "=", True),
]
ctx = self.env.context.copy()
ctx.update(
{
"default_partner_ids": self.ids,
"default_is_assortment": True,
"product_assortment": True,
}
)
action["context"] = ctx
return action
def _update_partner_assortments(self):
# Using sudo to contemplate evaluation of domains with restricted fields
self = self.sudo()
assortments = self.env["ir.filters"].search([("is_assortment", "=", True)])
for partner in self:
# Use ids instead of record to improve performance (Remove in next versions)
partner_assortment_ids = []
for assortment in assortments:
if partner in assortment.partner_ids or partner.filtered_domain(
assortment._get_eval_partner_domain()
):
partner_assortment_ids.append(assortment.id)
partner.applied_assortment_ids = assortments.browse(partner_assortment_ids)
@api.model_create_multi
def create(self, vals_list):
partners = super().create(vals_list)
self._update_partner_assortments()
return partners
def write(self, vals):
res = super().write(vals)
IrFilters = self.env["ir.filters"]
if IrFilters.get_partner_domain_fields() & set(vals.keys()):
self._update_partner_assortments()
return res
| 36.639344
| 2,235
|
618
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
{
"name": "Product Supplier Info Archive",
"summary": """
Add the active field to the product supplier info
""",
"version": "15.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/product-attribute",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"depends": ["product"],
"data": ["views/product_views.xml"],
"installable": True,
"maintainers": ["GuillemCForgeFlow", "AlvaroTForgeFlow", "OriolVForgeFlow"],
}
| 36.352941
| 618
|
286
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import fields, models
class ProductSupplierinfo(models.Model):
_inherit = "product.supplierinfo"
active = fields.Boolean(default=True)
| 28.6
| 286
|
694
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Template Tags",
"summary": "This addon allow to add tags on products",
"version": "15.0.1.0.1",
"license": "AGPL-3",
"author": "ACSONE SA/NV, Odoo Community Association (OCA), Numigi",
"website": "https://github.com/OCA/product-attribute",
"depends": ["product"],
"data": [
"security/product_template_rule.xml",
"security/product_template_tag.xml",
"views/product_product.xml",
"views/product_template.xml",
"views/product_template_tag.xml",
],
"maintainers": ["patrickrwilson", "ivantodorovich"],
}
| 34.7
| 694
|
1,648
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from psycopg2 import IntegrityError
from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger
class TestProductTemplateTagBase(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.product_tmpl = cls.env["product.template"].create({"name": "Test Product"})
class TestProductTemplateTag(TestProductTemplateTagBase):
def test_product_template_tag(self):
product_tmpl_tag = self.env["product.template.tag"].create(
{"name": "Test Tag", "product_tmpl_ids": [(6, 0, [self.product_tmpl.id])]}
)
product_tmpl_tag._compute_products_count()
self.assertEqual(product_tmpl_tag.products_count, 1)
def test_product_template_tag_uniq(self):
product_tmpl_tag = self.env["product.template.tag"].create({"name": "Test Tag"})
self.assertTrue(product_tmpl_tag)
# test same tag and same company
with mute_logger("odoo.sql_db"):
with self.assertRaises(IntegrityError):
with self.cr.savepoint():
self.env["product.template.tag"].create({"name": "Test Tag"})
# test same tag and different company
company = self.env["res.company"].create({"name": "Test"})
same_product_tmpl_tag_diff_company = self.env["product.template.tag"].create(
{"name": "Test Tag", "company_id": company.id}
)
self.assertTrue(same_product_tmpl_tag_diff_company)
| 41.2
| 1,648
|
1,620
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductTemplateTag(models.Model):
_name = "product.template.tag"
_description = "Product Tag"
_order = "sequence, name"
name = fields.Char(required=True, translate=True)
sequence = fields.Integer(default=10)
color = fields.Integer(string="Color Index")
product_tmpl_ids = fields.Many2many(
comodel_name="product.template",
string="Products",
relation="product_template_product_tag_rel",
column1="tag_id",
column2="product_tmpl_id",
)
products_count = fields.Integer(
string="# of Products", compute="_compute_products_count"
)
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
default=lambda self: self.env.company,
)
_sql_constraints = [
(
"name_uniq",
"unique(name, company_id)",
"Tag name must be unique inside a company",
),
]
@api.depends("product_tmpl_ids")
def _compute_products_count(self):
tag_id_product_count = {}
if self.ids:
self.env.cr.execute(
"""SELECT tag_id, COUNT(*)
FROM product_template_product_tag_rel
WHERE tag_id IN %s
GROUP BY tag_id""",
(tuple(self.ids),),
)
tag_id_product_count = dict(self.env.cr.fetchall())
for rec in self:
rec.products_count = tag_id_product_count.get(rec.id, 0)
| 31.153846
| 1,620
|
422
|
py
|
PYTHON
|
15.0
|
# Copyright 2017 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
tag_ids = fields.Many2many(
comodel_name="product.template.tag",
string="Tags",
relation="product_template_product_tag_rel",
column1="product_tmpl_id",
column2="tag_id",
)
| 24.823529
| 422
|
614
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Product Code Mandatory",
"summary": "Set Product Internal Reference as a required field",
"version": "15.0.1.0.1",
"license": "AGPL-3",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"depends": ["product"],
"data": ["data/product_code_seq.xml", "views/product_view.xml"],
"pre_init_hook": "pre_init_product_code",
"installable": True,
}
| 38.375
| 614
|
503
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestProductCode(TransactionCase):
def setUp(self):
super(TestProductCode, self).setUp()
self.product_model = self.env["product.product"]
self.product = self.product_model.create({"name": "Test Product Code"})
def test_product_code(self):
"""Check Product Code"""
self.assertTrue(self.product.default_code, "Product code is not set.")
| 35.928571
| 503
|
440
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2018 - TODAY, Open Source Integrators License AGPL-3.0
# or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ProductProduct(models.Model):
_inherit = "product.product"
def _get_default_code(self):
return self.env["ir.sequence"].next_by_code("product.default.code")
default_code = fields.Char(
"Internal Reference", index=True, default=_get_default_code
)
| 29.333333
| 440
|
506
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
def pre_init_hook(cr): # pragma: no cover
"""
Updates existing codes matching the default '/' or
empty. Primarily this ensures installation does not
fail for demo data.
:param cr: database cursor
:return: void
"""
cr.execute(
"UPDATE product_category "
"SET code = name || '-' || id "
"WHERE code IS NULL OR code = '/';"
)
| 29.764706
| 506
|
633
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Category Code Unique",
"summary": """
Allows to set product category code field as unique""",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"maintainers": ["rousseldenis", "luisg123v"],
"website": "https://github.com/OCA/product-attribute",
"depends": [
"product",
"product_category_code",
],
"data": [
"data/product_category_sequence.xml",
],
"pre_init_hook": "pre_init_hook",
}
| 30.142857
| 633
|
1,115
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from psycopg2 import IntegrityError
import odoo.tests.common as common
from odoo.tools import mute_logger
class TestProductCode(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
vals = {
"name": "Category Test",
"code": "TEST",
}
cls.category = cls.env["product.category"].create(vals)
@mute_logger("odoo.sql_db")
def test_category_code_unique(self):
vals = {
"name": "Category Test duplicate",
"code": "TEST",
}
with self.assertRaises(IntegrityError), self.env.cr.savepoint():
self.env["product.category"].create(vals)
vals.update({"code": "TEST1"})
self.env["product.category"].create(vals)
vals = {
"name": "Category Auto",
}
self.category_2 = self.env["product.category"].create(vals)
self.assertIn(
"PC/",
self.category_2.code,
)
| 29.342105
| 1,115
|
900
|
py
|
PYTHON
|
15.0
|
# Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
class ProductCategory(models.Model):
_inherit = "product.category"
_sql_constraints = [
("uniq_code", "unique(code)", "The category code must be unique!"),
]
@api.model
def _get_next_code(self):
return self.env["ir.sequence"].next_by_code("product.category")
@api.model
def create(self, vals):
if "code" not in vals or vals["code"] == "/":
vals["code"] = self._get_next_code()
return super().create(vals)
def write(self, vals):
for category in self:
value = vals.copy()
code = value.setdefault("code", category.code)
if code in [False, "/"]:
value["code"] = self._get_next_code()
super().write(value)
return True
| 28.125
| 900
|
808
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2019 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
def pre_init_product_code(cr):
cr.execute(
"""UPDATE product_product
SET default_code = 'DEFAULT' || nextval('ir_default_id_seq')
WHERE id in (SELECT distinct(pp.id)
FROM product_product pp
INNER JOIN (SELECT default_code, COUNT(*)
FROM product_product
GROUP BY default_code
HAVING COUNT(*)>1
)pp1 on pp.default_code=pp1.default_code
or pp.default_code is NULL
or LENGTH(pp.default_code) = 0)"""
)
return True
| 42.526316
| 808
|
545
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Unique Product Internal Reference",
"summary": "Set Product Internal Reference as Unique",
"version": "15.0.1.0.1",
"license": "AGPL-3",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"depends": ["product"],
"pre_init_hook": "pre_init_product_code",
"installable": True,
}
| 36.333333
| 545
|
1,020
|
py
|
PYTHON
|
15.0
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import psycopg2
from odoo.tests.common import TransactionCase
from odoo.tools.misc import mute_logger
class TestCodeUnique(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.product_obj = cls.env["product.product"]
cls.product1 = cls.product_obj.create(
{"name": "Test Product 1", "default_code": "TSTP1"}
)
def test_01_check_code_other(self):
self.product2 = self.product_obj.with_context(
check_default_code_unique=True
).create({"name": "Test Product 2", "default_code": "TSTP2"})
def test_02_check_code_unique(self):
with self.assertRaises(psycopg2.IntegrityError):
with mute_logger("odoo.sql_db"), self.cr.savepoint():
self.product2 = self.product_obj.with_context(
check_default_code_unique=True
).create({"name": "Test Product 2", "default_code": "TSTP1"})
| 36.428571
| 1,020
|
1,497
|
py
|
PYTHON
|
15.0
|
# Copyright (C) 2018 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
from odoo.tools import config
class ProductProduct(models.Model):
_inherit = "product.product"
_sql_constraints = [
(
"default_code_uniq",
"unique(default_code)",
"Internal Reference must be unique across the database!",
)
]
@api.model
def create(self, vals):
"""
Avoid create products with the same default code for testing other modules.
In this common test setup:
https://github.com/odoo/odoo/blob/15.0/addons/sale/tests/common.py#L99
Odoo creates three products with the same default_code (FURN_9999) and others.
If you have installed this module which adds a sql_constraint and use this in
common setup for testing in your CI will fail.
"""
if (
config["test_enable"]
and "default_code" in vals
and not self.env.context.get("check_default_code_unique")
):
products = (
self.env["product.product"]
.with_context(active_test=False)
.search([("default_code", "ilike", vals["default_code"])])
)
if products:
vals["default_code"] = vals["default_code"] + "/{}".format(
len(products)
)
return super().create(vals)
| 34.813953
| 1,497
|
501
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Lot Sequence",
"summary": """
Adds ability to define a lot sequence from the product""",
"version": "15.0.1.1.2",
"license": "AGPL-3",
"author": "ForgeFlow S.L., Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"depends": ["stock"],
"data": ["data/ir_config_parameter.xml", "views/product_views.xml"],
}
| 35.785714
| 501
|
6,064
|
py
|
PYTHON
|
15.0
|
from odoo.tests import Form
from odoo.tests.common import TransactionCase
class TestProductLotSequence(TransactionCase):
"""Test product lot sequence."""
def setUp(self):
super(TestProductLotSequence, self).setUp()
self.product_product = self.env["product.product"]
self.stock_production_lot = self.env["stock.production.lot"]
self.receipt_type = self.env.ref("stock.picking_type_in")
self.delivery_type = self.env.ref("stock.picking_type_out")
def _create_picking(self, picking_type, move_vals_list):
picking_form = Form(self.env["stock.picking"])
picking_form.picking_type_id = picking_type
for move_vals in move_vals_list:
with picking_form.move_ids_without_package.new() as move_form:
move_form.product_id = move_vals.get("product_id")
move_form.product_uom_qty = move_vals.get("product_uom_qty", 1.0)
move_form.product_uom = move_vals.get(
"product_uom", self.env.ref("uom.product_uom_unit")
)
picking = picking_form.save()
picking.action_confirm()
return picking
def test_product_sequence(self):
self.assertEqual(self.stock_production_lot._get_sequence_policy(), "product")
product = self.product_product.create(
dict(name="The bar of foo", tracking="serial")
)
self.assertTrue(product.lot_sequence_id)
product.lot_sequence_id.write(
dict(
prefix="foo/",
padding=5,
number_increment=1,
number_next_actual=1,
suffix="/bar",
)
)
next_serial = self.env["stock.production.lot"]._get_next_serial(
self.env.company, product
)
self.assertRegexpMatches(next_serial, r"foo/\d{5}/bar")
def test_lot_onchange_product_id(self):
self.assertEqual(self.stock_production_lot._get_sequence_policy(), "product")
product = self.product_product.create(dict(name="Shiba plush", tracking="lot"))
self.assertTrue(product.lot_sequence_id)
product.lot_sequence_id.write(
dict(prefix="shiba/", padding=4, number_increment=1, number_next_actual=1)
)
lot_form = Form(self.stock_production_lot)
lot_form.product_id = product
lot_form.company_id = self.env.company
lot = lot_form.save()
self.assertRegexpMatches(lot.name, r"shiba/\d{4}$")
def test_global_sequence(self):
self.env["ir.config_parameter"].set_param(
"product_lot_sequence.policy", "global"
)
product_1 = self.product_product.create(
{"name": "Test global 1", "tracking": "serial"}
)
self.assertFalse(product_1.lot_sequence_id)
product_2 = self.product_product.create(
{"name": "Test global 2", "tracking": "lot"}
)
self.assertFalse(product_2.lot_sequence_id)
seq = self.env["ir.sequence"].search([("code", "=", "stock.lot.serial")])
next_sequence_number = seq.get_next_char(seq.number_next_actual)
next_serial = self.env["stock.production.lot"]._get_next_serial(
self.env.company, product_1
)
self.assertEqual(next_serial, next_sequence_number)
seq._get_number_next_actual()
next_sequence_number_2 = seq.get_next_char(seq.number_next_actual)
next_serial_2 = self.env["stock.production.lot"]._get_next_serial(
self.env.company, product_2
)
self.assertEqual(next_serial_2, next_sequence_number_2)
def test_lot_onchange_product_id_global(self):
self.env["ir.config_parameter"].set_param(
"product_lot_sequence.policy", "global"
)
product = self.product_product.create(
{"name": "Test global", "tracking": "serial"}
)
self.assertFalse(product.lot_sequence_id)
seq = self.env["ir.sequence"].search([("code", "=", "stock.lot.serial")])
next_sequence_number = seq.get_next_char(seq.number_next_actual)
lot_form = Form(
self.stock_production_lot.with_context(
default_company_id=self.env.company.id
)
)
self.assertEqual(lot_form.name, next_sequence_number)
self.assertEqual(lot_form.company_id, self.env.company)
lot_form.product_id = product
lot = lot_form.save()
self.assertEqual(lot.name, next_sequence_number)
def test_open_detailed_operations(self):
self.env["ir.config_parameter"].set_param(
"product_lot_sequence.policy", "global"
)
seq = self.env["ir.sequence"].search([("code", "=", "stock.lot.serial")])
first_next_sequence_number = seq.get_next_char(seq.number_next_actual)
product = self.product_product.create(
{"name": "Test global", "tracking": "serial"}
)
delivery_picking = self._create_picking(
self.delivery_type, [{"product_id": product}]
)
delivery_move = delivery_picking.move_lines
self.assertFalse(delivery_move.next_serial)
delivery_move.action_show_details()
self.assertFalse(delivery_move.next_serial)
self.assertEqual(
seq.get_next_char(seq.number_next_actual), first_next_sequence_number
)
receipt_picking = self._create_picking(
self.receipt_type, [{"product_id": product}]
)
receipt_move = receipt_picking.move_lines
self.assertFalse(receipt_move.next_serial)
receipt_move.action_show_details()
self.assertEqual(receipt_move.next_serial, first_next_sequence_number)
new_next_sequence_number = seq.get_next_char(seq.number_next_actual)
self.assertNotEqual(new_next_sequence_number, first_next_sequence_number)
receipt_move.action_show_details()
self.assertEqual(
new_next_sequence_number, seq.get_next_char(seq.number_next_actual)
)
| 43.625899
| 6,064
|
1,026
|
py
|
PYTHON
|
15.0
|
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import models
class StockMove(models.Model):
_inherit = "stock.move"
def action_show_details(self):
"""Avoid calling and incrementing the sequence if not needed or already done"""
seq_policy = self.env["stock.production.lot"]._get_sequence_policy()
if seq_policy in ("product", "global"):
# If move is not supposed to assign serial pass empty string for next serial
if not self.display_assign_serial:
return super(
StockMove, self.with_context(force_next_serial="")
).action_show_details()
# If the sequence was already called once, avoid calling it another time
elif self.next_serial:
return super(
StockMove, self.with_context(force_next_serial=self.next_serial)
).action_show_details()
return super().action_show_details()
| 44.608696
| 1,026
|
2,511
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductionLot(models.Model):
_inherit = "stock.production.lot"
name = fields.Char(default=lambda self: self._default_name())
@api.model
def _get_sequence_policy(self):
return (
self.env["ir.config_parameter"]
.sudo()
.get_param("product_lot_sequence.policy")
)
@api.model
def _default_name(self):
seq_policy = self._get_sequence_policy()
if seq_policy != "product":
return self.env["ir.sequence"].next_by_code("stock.lot.serial")
return ""
@api.onchange("product_id")
def onchange_product_id(self):
seq_policy = self._get_sequence_policy()
if (
seq_policy == "product"
and self.product_id
and self.product_id.product_tmpl_id.lot_sequence_id
):
self.name = self.product_id.product_tmpl_id.lot_sequence_id._next()
@api.model_create_multi
def create(self, vals_list):
seq_policy = self._get_sequence_policy()
if seq_policy in ["product", "global"]:
for lot_vals in vals_list:
if "name" not in lot_vals:
if seq_policy == "product":
product = self.env["product.product"].browse(
lot_vals["product_id"]
)
if product and product.product_tmpl_id.lot_sequence_id:
lot_vals[
"name"
] = product.product_tmpl_id.lot_sequence_id._next()
else:
lot_vals["name"] = self.env["ir.sequence"].next_by_code(
"stock.lot.serial"
)
return super(ProductionLot, self).create(vals_list)
@api.model
def _get_next_serial(self, company, product):
if "force_next_serial" in self.env.context:
return self.env.context.get("force_next_serial")
seq_policy = self._get_sequence_policy()
if seq_policy == "product":
seq = product.product_tmpl_id.lot_sequence_id
if seq:
return seq._next()
elif seq_policy == "global":
return self.env["ir.sequence"].next_by_code("stock.lot.serial")
return super()._get_next_serial(company, product)
| 36.926471
| 2,511
|
4,947
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
lot_sequence_id = fields.Many2one(
"ir.sequence",
string="Entry Sequence",
help="This field contains the information related to the numbering of lots.",
copy=False,
)
lot_sequence_prefix = fields.Char(
string="Sequence Prefix",
help="The lot's sequence will be created using this prefix.",
)
lot_sequence_padding = fields.Integer(
string="Sequence Number of Digits",
default=7,
help="The lots' sequence will be created using this number of digits.",
)
lot_sequence_number_next = fields.Integer(
string="Next Number",
help="The next sequence number will be used for the next lot.",
compute="_compute_lot_seq_number_next",
inverse="_inverse_lot_seq_number_next",
)
display_lot_sequence_fields = fields.Boolean(
compute="_compute_display_lot_sequence_fields"
)
def _compute_display_lot_sequence_fields(self):
self.display_lot_sequence_fields = (
self.env["stock.production.lot"]._get_sequence_policy() == "product"
)
@api.model
def _create_lot_sequence(self, vals):
"""Create new no_gap entry sequence"""
name = vals.get("name", False) or self.name
prefix = vals.get("lot_sequence_prefix", False) or self.lot_sequence_prefix
padding = vals.get("lot_sequence_padding") or self.lot_sequence_padding
seq = {
"name": name,
"implementation": "no_gap",
"prefix": prefix,
"padding": padding,
"number_increment": 1,
"use_date_range": False,
}
seq = self.env["ir.sequence"].create(seq)
seq_date_range = seq._get_current_sequence()
seq_date_range.number_next = self.lot_sequence_number_next or vals.get(
"lot_sequence_number_next", 1
)
return seq
# do not depend on 'lot_sequence_id.date_range_ids', because
# lot_sequence_id._get_current_sequence() may invalidate it!
@api.depends("lot_sequence_id.use_date_range", "lot_sequence_id.number_next_actual")
def _compute_lot_seq_number_next(self):
"""
Compute 'lot_sequence_number_next' according to the current sequence in use, an
ir.sequence or an ir.sequence.date_range.
"""
for template in self:
if template.lot_sequence_id:
sequence = template.lot_sequence_id._get_current_sequence()
template.lot_sequence_number_next = sequence.number_next_actual
else:
template.lot_sequence_number_next = 1
def _inverse_lot_seq_number_next(self):
"""
Inverse 'lot_sequence_number_next' to edit the current sequence next number
"""
for template in self:
if template.lot_sequence_id and template.lot_sequence_number_next:
sequence = template.lot_sequence_id._get_current_sequence()
sequence.sudo().number_next = template.lot_sequence_number_next
def write(self, vals):
seq_policy = self.env["stock.production.lot"]._get_sequence_policy()
if seq_policy == "product":
for template in self:
tracking = vals.get("tracking", False) or template.tracking
if tracking in ["lot", "serial"]:
if (
not vals.get("lot_sequence_id", False)
and not template.lot_sequence_id
):
vals["lot_sequence_id"] = (
template.sudo()._create_lot_sequence(vals).id
)
elif vals.get("lot_sequence_id", False):
lot_sequence_id = self.env["ir.sequence"].browse(
vals["lot_sequence_id"]
)
vals["lot_sequence_prefix"] = lot_sequence_id.prefix
vals["lot_sequence_padding"] = lot_sequence_id.padding
return super().write(vals)
@api.model
def create(self, vals):
seq_policy = self.env["stock.production.lot"]._get_sequence_policy()
if seq_policy == "product" and vals.get("tracking", False) in ["lot", "serial"]:
if not vals.get("lot_sequence_id", False):
vals["lot_sequence_id"] = self.sudo()._create_lot_sequence(vals).id
else:
lot_sequence_id = self.env["ir.sequence"].browse(
vals["lot_sequence_id"]
)
vals["lot_sequence_prefix"] = lot_sequence_id.prefix
vals["lot_sequence_padding"] = lot_sequence_id.padding
return super().create(vals)
| 41.923729
| 4,947
|
495
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 ForgeFlow S.L.
# (http://www.forgeflow.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Restricted Type",
"version": "15.0.1.0.0",
"author": "ForgeFlow," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
"category": "Product",
"depends": ["product"],
"data": ["views/product_views.xml"],
"auto_install": False,
"installable": True,
}
| 30.9375
| 495
|
2,146
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase
class TestProductRestrictedType(TransactionCase):
def setUp(self):
super(TestProductRestrictedType, self).setUp()
self.product_product = self.env["product.product"]
self.product_category = self.env["product.category"]
self.product_types = self.env["product.template"]._fields["type"].selection
self.categ_test = self.product_category.create(
{
"name": "Test Category 1",
"restricted_product_type": self.product_types[0][0],
}
)
self.categ_test2 = self.product_category.create({"name": "Test Category 2"})
self.product_test = self.product_product.create(
{
"name": "Test Product 1",
"type": self.product_types[0][0],
"categ_id": self.categ_test.id,
}
)
self.product_product.create(
{
"name": "Test Product 2",
"type": self.product_types[1][0],
"categ_id": self.categ_test2.id,
}
)
def test_product_different_type(self):
"""User tries to change product type to a different type than
company restricted product type"""
with self.assertRaises(ValidationError):
self.product_test.write({"type": self.product_types[1][0]})
with self.assertRaises(ValidationError):
self.product_product.create(
{
"name": "Test Product 3",
"type": self.product_types[1][0],
"categ_id": self.categ_test.id,
}
)
def test_category_different_type(self):
"""User tries to change category restricted type but there are
products with already defined (different) type"""
with self.assertRaises(ValidationError):
self.categ_test.write({"restricted_product_type": self.product_types[1][0]})
| 38.321429
| 2,146
|
1,259
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, models
from odoo.exceptions import ValidationError
class ProductTemplate(models.Model):
_inherit = "product.template"
@api.onchange("categ_id")
def _onchange_categ_id(self):
if self.categ_id and self.categ_id.restricted_product_type:
self.type = self.categ_id.restricted_product_type
@api.onchange("type")
def _onchange_type(self):
if self.type:
return {
"domain": {
"categ_id": [("restricted_product_type", "in", [self.type, False])]
}
}
else:
return {"domain": {"categ_id": []}}
@api.constrains("type")
def _check_product_type(self):
for product in self:
if (
product.categ_id.restricted_product_type
and product.type != product.categ_id.restricted_product_type
):
raise ValidationError(
_(
"The product type must be equal to the restricted "
"product type defined in the product category"
)
)
| 33.131579
| 1,259
|
1,306
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ProductCategory(models.Model):
_inherit = "product.category"
restricted_product_type = fields.Selection(
string="Restricted Product Type ",
selection=lambda self: self.env["product.template"]._fields["type"].selection,
)
@api.constrains("restricted_product_type")
def _check_restricted_product_type(self):
"""Check if any product in the category has different type"""
for categ in self:
if categ.restricted_product_type:
products = self.env["product.template"].search(
[
("categ_id", "=", categ.id),
("type", "!=", categ.restricted_product_type),
],
limit=1,
)
if products:
raise ValidationError(
_(
"A product (or multiple products) in the category "
"have different type than the selected restricted "
"product type"
)
)
| 38.411765
| 1,306
|
644
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Akretion (https://www.akretion.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Product logistics UoM",
"summary": "Configure product weights and volume UoM",
"version": "15.0.1.0.1",
"development_status": "Beta",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"author": " Akretion, Odoo Community Association (OCA)",
"maintainers": ["hparfr"],
"license": "AGPL-3",
"installable": True,
"depends": [
"product",
],
"data": [
"views/res_config_settings.xml",
"views/product.xml",
],
}
| 30.666667
| 644
|
2,602
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Akretion (https://www.akretion.com).
# @author Raphaël Reverdy <raphael.reverdy@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
volume_uom_id = fields.Many2one(
"uom.uom",
string="Volume Unit of Measure",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_vol").id)
],
default=lambda x: x._get_volume_uom_id_from_ir_config_parameter(),
)
volume_uom_name = fields.Char(
string="Volume unit of measure label",
related="volume_uom_id.name",
readonly=True,
)
weight_uom_id = fields.Many2one(
"uom.uom",
string="Weight Unit of Measure",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_kgm").id)
],
compute=False,
default=lambda x: x._get_weight_uom_id_from_ir_config_parameter(),
)
weight_uom_name = fields.Char(
string="Weight unit of measure label",
related="weight_uom_id.name",
readonly=True,
)
product_uom_readonly = fields.Boolean(compute="_compute_product_uom_readonly")
def _compute_product_uom_readonly(self):
# helper for view form
self.product_uom_readonly = not self.env.user.has_group("uom.group_uom")
@api.model
def _get_volume_uom_id_from_ir_config_parameter(self):
get_param = self.env["ir.config_parameter"].sudo().get_param
default_uom = get_param("product_default_volume_uom_id")
if default_uom:
return self.env["uom.uom"].browse(int(default_uom))
else:
return super()._get_volume_uom_id_from_ir_config_parameter()
@api.model
def _get_weight_uom_id_from_ir_config_parameter(self):
get_param = self.env["ir.config_parameter"].sudo().get_param
default_uom = get_param("product_default_weight_uom_id")
if default_uom:
return self.env["uom.uom"].browse(int(default_uom))
else:
return super()._get_weight_uom_id_from_ir_config_parameter()
@api.model
def _get_length_uom_id_from_ir_config_parameter(self):
get_param = self.env["ir.config_parameter"].sudo().get_param
default_uom = get_param("product_default_length_uom_id")
if default_uom:
return self.env["uom.uom"].browse(int(default_uom))
else:
return super()._get_length_uom_id_from_ir_config_parameter()
| 36.125
| 2,601
|
1,387
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Akretion (https://www.akretion.com).
# @author Raphaël Reverdy <raphael.reverdy@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
product_default_weight_uom_id = fields.Many2one(
"uom.uom",
"Default Weight Unit of Measure",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_kgm").id)
],
config_parameter="product_default_weight_uom_id",
help="Default unit of measure to express product weight",
)
product_default_volume_uom_id = fields.Many2one(
"uom.uom",
"Default Volume Unit of Measure",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.product_uom_categ_vol").id)
],
config_parameter="product_default_volume_uom_id",
help="Default unit of measure to express product volume",
)
product_default_length_uom_id = fields.Many2one(
"uom.uom",
"Default Length Unit of Measure",
domain=lambda self: [
("category_id", "=", self.env.ref("uom.uom_categ_length").id)
],
config_parameter="product_default_length_uom_id",
help="Default unit of measure to express product length",
)
| 35.538462
| 1,386
|
650
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Product Cost Security",
"summary": "Product cost security restriction view",
"version": "15.0.2.0.0",
"development_status": "Production/Stable",
"maintainers": ["sergio-teruel"],
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["product"],
"data": ["security/product_cost_security.xml", "views/product_views.xml"],
}
| 38.235294
| 650
|
819
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Sergio Teruel - Tecnativa <sergio.teruel@tecnativa.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
standard_price = fields.Float(groups="product_cost_security.group_product_cost")
user_can_update_cost = fields.Boolean(compute="_compute_user_can_update_cost")
@api.depends_context("uid")
def _compute_user_can_update_cost(self):
"""A user could have full cost permissions but no product edition permissions.
We want to prevent those from updating costs."""
for product in self:
product.user_can_update_cost = self.env.user.has_group(
"product_cost_security.group_product_edit_cost"
)
| 43.105263
| 819
|
332
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Sergio Teruel - Tecnativa <sergio.teruel@tecnativa.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ProductProduct(models.Model):
_inherit = "product.product"
standard_price = fields.Float(groups="product_cost_security.group_product_cost")
| 36.888889
| 332
|
613
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Carlos Dauden - Tecnativa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Product Pricelist Revision",
"summary": "Product Pricelist Revision",
"version": "15.0.1.0.0",
"category": "Product",
"website": "https://github.com/OCA/product-attribute",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["sale_management"],
"data": [
"security/ir.model.access.csv",
"views/pricelist_view.xml",
"wizards/pricelist_duplicate_wizard_view.xml",
],
}
| 32.263158
| 613
|
4,583
|
py
|
PYTHON
|
15.0
|
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import datetime
from odoo.tests.common import TransactionCase
class TestProductPricelistRevision(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.pricelist_obj = cls.env["product.pricelist"]
cls.pricelist_item_obj = cls.env["product.pricelist.item"]
cls.product_category_obj = cls.env["product.category"]
cls.product_template_obj = cls.env["product.template"]
cls.product_product_obj = cls.env["product.product"]
# Create a price list, a product category, a product template and
# a product variant
cls.pricelist = cls.pricelist_obj.create(
{"name": "Pricelist", "item_ids": False}
)
cls.product_category = cls.product_category_obj.create(
{"name": "Product Category"}
)
cls.product_template = cls.product_template_obj.create(
{"name": "Product Template", "categ_id": cls.product_category.id}
)
cls.product_product = cls.product_product_obj.create(
{"name": "Product Variant", "categ_id": cls.product_category.id}
)
# Create pricelist items
cls.pricelist_item_global = cls.pricelist_item_obj.create(
{
"pricelist_id": cls.pricelist.id,
"compute_price": "formula",
"price_discount": 15,
}
)
cls.pricelist_item_product_category = cls.pricelist_item_obj.create(
{
"pricelist_id": cls.pricelist.id,
"applied_on": "2_product_category",
"categ_id": cls.product_category.id,
"compute_price": "formula",
"price_discount": 10,
}
)
cls.pricelist_item_product_template = cls.pricelist_item_obj.create(
{
"pricelist_id": cls.pricelist.id,
"applied_on": "1_product",
"product_tmpl_id": cls.product_template.id,
"compute_price": "percentage",
"percent_price": 5,
}
)
cls.pricelist_item_product_product = cls.pricelist_item_obj.create(
{
"pricelist_id": cls.pricelist.id,
"applied_on": "0_product_variant",
"product_id": cls.product_product.id,
"compute_price": "fixed",
"fixed_price": 100,
}
)
def test_search_name(self):
item_obj = self.pricelist_item_obj
result = item_obj.search([("name", "ilike", "product")])
expected = self.pricelist_item_product_category
expected |= self.pricelist_item_product_template
expected |= self.pricelist_item_product_product
self.assertEqual(result, expected)
result = item_obj.search([("name", "ilike", "product category")])
self.assertEqual(result, self.pricelist_item_product_category)
result = item_obj.search([("name", "ilike", "product template")])
self.assertEqual(result, self.pricelist_item_product_template)
result = item_obj.search([("name", "ilike", "product variant")])
self.assertEqual(result, self.pricelist_item_product_product)
result = item_obj.search([("name", "ilike", "all")])
self.assertEqual(len(result), 0)
def test_wizard_action_apply_and_compute_variation_percent(self):
wizard_obj = self.env["product.pricelist.item.duplicate.wizard"]
# Before duplicate there are 4 items
self.assertEqual(len(self.pricelist.item_ids), 4)
items_before_wizard = self.pricelist.item_ids
# Create wizard from pricelist_item_product_product and aply
active_ids = self.pricelist_item_product_product.ids
wizard = wizard_obj.with_context(active_ids=active_ids).create(
{
"date_start": datetime.now(),
"date_end": datetime.now(),
"variation_percent": 50,
}
)
wizard.action_apply()
# There will be one more item in self.pricelist
self.assertEqual(len(self.pricelist.item_ids), 5)
new_item = self.pricelist.item_ids - items_before_wizard
self.assertEqual(new_item.previous_item_id.id, active_ids[0])
self.assertEqual(new_item.previous_price, 100)
self.assertEqual(new_item.fixed_price, 150)
self.assertEqual(new_item.variation_percent, 50)
| 43.647619
| 4,583
|
1,406
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Carlos Dauden - Tecnativa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductPricelistItem(models.Model):
_inherit = "product.pricelist.item"
name = fields.Char(search="_search_name")
previous_item_id = fields.Many2one(
comodel_name="product.pricelist.item",
string="Previous Item",
help="Relation with previous item when duplicate line",
)
previous_price = fields.Float(
related="previous_item_id.fixed_price", string="Previous Fixed Price"
)
variation_percent = fields.Float(
compute="_compute_variation_percent",
store=True,
digits="Product Price",
string="Variation %",
)
@api.model
def _search_name(self, operator, value):
return [
"|",
"|",
("categ_id", operator, value),
("product_tmpl_id", operator, value),
("product_id", operator, value),
]
@api.depends("fixed_price", "previous_item_id.fixed_price")
def _compute_variation_percent(self):
for line in self:
if not (line.fixed_price and line.previous_price):
line.variation_percent = 0.0
else:
line.variation_percent = (
line.fixed_price / line.previous_price - 1
) * 100
| 31.244444
| 1,406
|
1,487
|
py
|
PYTHON
|
15.0
|
# Copyright 2018 Carlos Dauden - Tecnativa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from dateutil.relativedelta import relativedelta
from odoo import fields, models
class ProductPricelistItemDuplicateWizard(models.TransientModel):
_name = "product.pricelist.item.duplicate.wizard"
_description = "Wizard Product Pricelist Item Duplicate"
date_start = fields.Datetime(required=True)
date_end = fields.Datetime()
variation_percent = fields.Float(digits="Product Price", string="Variation %")
def action_apply(self):
PricelistItem = self.env["product.pricelist.item"]
new_items = PricelistItem
for item in PricelistItem.browse(self.env.context["active_ids"]):
new_items |= item.copy(
{
"date_start": self.date_start,
"date_end": self.date_end,
"previous_item_id": item.id,
"fixed_price": item.fixed_price
* (1.0 + self.variation_percent / 100.0),
}
)
item.date_end = self.date_start - relativedelta(seconds=1)
xmlid = "product_pricelist_revision.product_pricelist_item_action"
action = self.env["ir.actions.act_window"]._for_xml_id(xmlid)
if len(new_items) > 0:
action["domain"] = [("id", "in", new_items.ids)]
else:
action = {"type": "ir.actions.act_window_close"}
return action
| 39.131579
| 1,487
|
487
|
py
|
PYTHON
|
15.0
|
# Copyright 2020 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Product Category Active",
"version": "15.0.1.0.0",
"category": "Product",
"summary": "Add option to archive product categories",
"author": "Tecnativa, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"license": "AGPL-3",
"depends": ["product"],
"data": ["views/product_views.xml"],
}
| 34.785714
| 487
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.