-
-
Notifications
You must be signed in to change notification settings - Fork 720
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] product_internal_reference_generator: create sequence as sudo
- Loading branch information
1 parent
7b79aee
commit 57b7366
Showing
15 changed files
with
154 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from . import product_code_sequence | ||
from . import product_template | ||
from . import product_product | ||
from . import res_company | ||
from . import res_config_settings |
18 changes: 17 additions & 1 deletion
18
product_internal_reference_generator/models/product_code_sequence.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
# Copyright 2023 Ooops - Ilyas | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
from odoo import _, exceptions, fields, models | ||
|
||
|
||
class ProductCodeSequence(models.Model): | ||
_name = "product.code.sequence" | ||
_description = "Internal Reference Template" | ||
|
||
active = fields.Boolean(default=True) | ||
name = fields.Char(required=True) | ||
sequence_id = fields.Many2one("ir.sequence", required=True) | ||
variant_reference_numbers = fields.Integer("Digits", default=3, required=True) | ||
|
||
def unlink(self): | ||
for rec in self: | ||
products = self.env["product.template"].search( | ||
[("int_ref_template_id", "=", rec.id)] | ||
) | ||
if products: | ||
raise exceptions.ValidationError( | ||
_( | ||
"You can't delete %s template because there is products " | ||
"related to it. You can archive it instead." | ||
" Products: %s" % (rec.name, products.mapped("display_name")) | ||
) | ||
) | ||
return super().unlink() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
product_internal_reference_generator/models/res_company.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2023 Ooops - Ilyas | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
default_int_ref_template_id = fields.Many2one( | ||
"product.code.sequence", | ||
default_model="product.template", | ||
string="Default Internal Reference Template", | ||
) |
13 changes: 13 additions & 0 deletions
13
product_internal_reference_generator/models/res_config_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2023 Ooops - Ilyas | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl) | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
default_int_ref_template_id = fields.Many2one( | ||
related="company_id.default_int_ref_template_id", | ||
readonly=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="group_int_ref_template_always_visible" model="res.groups"> | ||
<field name="name">Internal reference template always visible</field> | ||
<field name="name">Internal reference template manager</field> | ||
<field name="category_id" ref="base.module_category_hidden" /> | ||
</record> | ||
<record id="group_int_ref_generate" model="res.groups"> | ||
<field name="name">Generate internal reference</field> | ||
<field name="category_id" ref="base.module_category_hidden" /> | ||
</record> | ||
</odoo> |
4 changes: 2 additions & 2 deletions
4
product_internal_reference_generator/security/ir.model.access.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
pcs1,pcs1,model_product_code_sequence,base.group_user,1,1,0,0 | ||
pcs2,pcs2,model_product_code_sequence,stock.group_stock_manager,1,1,1,1 | ||
pcs1,pcs1,model_product_code_sequence,base.group_user,1,0,0,0 | ||
pcs2,pcs2,model_product_code_sequence,product_internal_reference_generator.group_int_ref_template_always_visible,1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
product_internal_reference_generator/views/res_config_settings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="res_config_settings_view_form" model="ir.ui.view"> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="stock.res_config_settings_view_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//div[@id='manage_product_packaging']" position="after"> | ||
<div | ||
class="col-12 col-lg-6 o_setting_box" | ||
id="int_ref_template_id_setting" | ||
groups="product_internal_reference_generator.group_int_ref_template_always_visible,base.group_system" | ||
> | ||
<div class="o_setting_left_pane"> | ||
</div> | ||
<div class="o_setting_right_pane"> | ||
<label for="default_int_ref_template_id" /> | ||
<field name="default_int_ref_template_id" /> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |