Skip to content

Commit

Permalink
[IMP] product_profile_example: black, structure change
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkhao authored and bosd committed Jan 18, 2025
1 parent 5a84305 commit b16d227
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 69 deletions.
3 changes: 1 addition & 2 deletions product_profile_example/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding: utf-8
# © 2015 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import profile
from . import models
29 changes: 10 additions & 19 deletions product_profile_example/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
# coding: utf-8
# © 2015 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': 'Product Profile Example',
'summary': 'Product Profile Use Case',
'version': '10.0.1.0.1',
'author': 'Akretion, Odoo Community Association (OCA)',
'category': 'product',
'depends': [
'product_profile',
'purchase',
'point_of_sale',
'mrp',
],
'website': 'http://www.akretion.com/',
'demo': [
'product.profile.csv',
'product_product_demo.xml',
],
'installable': True,
'license': 'AGPL-3',
"name": "Product Profile Example",
"summary": "Product Profile Use Case",
"version": "10.0.1.0.1",
"author": "Akretion, Odoo Community Association (OCA)",
"category": "product",
"depends": ["product_profile", "purchase", "point_of_sale", "mrp",],
"website": "http://www.akretion.com/",
"demo": ["demo/product.profile.csv", "demo/product_product_demo.xml",],
"installable": True,
"license": "AGPL-3",
}
File renamed without changes.
4 changes: 4 additions & 0 deletions product_profile_example/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# © 2015 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import profile
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# coding: utf-8
# © 2015 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields


class ProductProfile(models.Model):
_inherit = 'product.profile'
_inherit = "product.profile"

type = fields.Selection(selection_add=[('product', 'Stockable Product')])
type = fields.Selection(selection_add=[("product", "Stockable Product")])

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')
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()
profile_default_route_ids = fields.Many2many(
'stock.location.route',
string='Routes',
"stock.location.route",
string="Routes",
domain="[('product_selectable', '=', True)]",
help="Depending on the modules installed, this will allow "
"you to define the route of the product: "
"whether it will be bought, manufactured, MTO/MTS,...")
"you to define the route of the product: "
"whether it will be bought, manufactured, MTO/MTS,...",
)
profile_default_categ_id = fields.Many2one(
'product.category',
string='Default category')
"product.category", string="Default category"
)
1 change: 0 additions & 1 deletion product_profile_example/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
# © 2015 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

Expand Down
73 changes: 39 additions & 34 deletions product_profile_example/tests/test_profile.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,89 @@
# coding: utf-8
# © 2016 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import TransactionCase


class TestProductProfile(TransactionCase):

def setUp(self):
super(TestProductProfile, self).setUp()
self.prd_m = self.env['product.product']
self.prd_m = self.env["product.product"]
# product 'HDD SH-2' in demo data
self.hard_disc_prd = self.env.ref('product.product_product_17')
self.my_own_profile = self.env.ref('product_profile_example.own')
self.hard_disc_prd = self.env.ref("product.product_product_17")
self.my_own_profile = self.env.ref("product_profile_example.own")
self.manufacturing_prof = self.env.ref(
'product_profile_example.manuf_prof')
"product_profile_example.manuf_prof"
)
self.analysis_tmpl = self.env.ref(
'point_of_sale.partner_product_7_product_template')
self.analysis_prd = self.env.ref(
'point_of_sale.partner_product_7')
self.theoritical_categ_id = self.env.ref('product.product_category_5')
self.categ = self.env.ref('product.product_category_3')
"point_of_sale.partner_product_7_product_template"
)
self.analysis_prd = self.env.ref("point_of_sale.partner_product_7")
self.theoritical_categ_id = self.env.ref("product.product_category_5")
self.categ = self.env.ref("product.product_category_3")

def test_check_hard_disc_product(self):
# check route_ids
real_routes = [x.id for x in self.hard_disc_prd.route_ids]
theoritical_routes = [
self.env.ref('mrp.route_warehouse0_manufacture').id,
self.env.ref('stock.route_warehouse0_mto').id,
self.env.ref("mrp.route_warehouse0_manufacture").id,
self.env.ref("stock.route_warehouse0_mto").id,
]
real_routes.sort()
theoritical_routes.sort()
self.assertEqual(real_routes, theoritical_routes)
# check categ_id
theoritical_categ_id = self.theoritical_categ_id
self.assertEqual(self.hard_disc_prd.categ_id.id,
theoritical_categ_id.id)
self.assertEqual(
self.hard_disc_prd.categ_id.id, theoritical_categ_id.id
)

def test_create_product(self):
name = 'only name is specified'
vals = {'profile_id': self.my_own_profile.id,
'name': name}
name = "only name is specified"
vals = {"profile_id": self.my_own_profile.id, "name": name}
new_product = self.prd_m.create(vals)
new_product._onchange_from_profile()
count_prd = self.prd_m.search([('name', '=', name)])
count_prd = self.prd_m.search([("name", "=", name)])
self.assertEqual(len(count_prd), 1)

def test_write_template(self):
vals = {'profile_id': self.my_own_profile.id}
vals = {"profile_id": self.my_own_profile.id}
self.analysis_tmpl.write(vals)
self.assertEqual(self.analysis_tmpl.profile_id, self.my_own_profile)

def test_write_product(self):
vals = {'profile_id': self.my_own_profile.id}
vals = {"profile_id": self.my_own_profile.id}
self.analysis_prd.write(vals)
self.assertEqual(self.analysis_prd.profile_id, self.my_own_profile)

def test_product_tmpl_fields_view_get(self):
view_id = self.env.ref('product.product_template_search_view').id
view_id = self.env.ref("product.product_template_search_view").id
res = self.hard_disc_prd.fields_view_get(
view_id=view_id, view_type='search')
self.assertTrue('string="My Own Type Saleable"' in res['arch'],
'string="My Own Type Saleable" must be in '
'fields_view_get() output')
view_id=view_id, view_type="search"
)
self.assertTrue(
'string="My Own Type Saleable"' in res["arch"],
'string="My Own Type Saleable" must be in '
"fields_view_get() output",
)

def test_impact_write_profile_model(self):
"""If profile is updated, products must be written too
on profile depends fields"""
self.manufacturing_prof.write({'type': 'consu'})
product = self.env['product.product'].search(
[('profile_id', '=', self.manufacturing_prof.id)])[0]
self.assertEqual(product.type, 'consu')
self.manufacturing_prof.write({"type": "consu"})
product = self.env["product.product"].search(
[("profile_id", "=", self.manufacturing_prof.id)]
)[0]
self.assertEqual(product.type, "consu")

def test_default_behavior(self):
"""Check if field prefixed with default_profile
have a default behavior on field values"""
categ = self.categ
consu_profile = self.env.ref('product_profile_example.consu_prof')
vals = {'profile_id': consu_profile.id,
'categ_id': categ.id,
'name': "Product with modified category"}
consu_profile = self.env.ref("product_profile_example.consu_prof")
vals = {
"profile_id": consu_profile.id,
"categ_id": categ.id,
"name": "Product with modified category",
}
new_product = self.prd_m.create(vals)
self.assertEqual(new_product.categ_id, categ)

0 comments on commit b16d227

Please sign in to comment.