-
-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
264 additions
and
110 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,31 +1,13 @@ | ||
# coding: utf-8 | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
from openerp import models, fields | ||
from odoo import models, fields | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = 'product.template' | ||
_inherit = "product.template" | ||
|
||
manufacturer = fields.Many2one('res.partner', 'Manufacturer') | ||
manufacturer_pname = fields.Char('Manuf. Product Name') | ||
manufacturer_pref = fields.Char('Manuf. Product Code') | ||
manufacturer_purl = fields.Char('Manuf. Product URL') | ||
manufacturer = fields.Many2one("res.partner", string="Manufacturer") | ||
manufacturer_pname = fields.Char(string="Manuf. Product Name") | ||
manufacturer_pref = fields.Char(string="Manuf. Product Code") | ||
manufacturer_purl = fields.Char(string="Manuf. Product URL") | ||
country_id = fields.Many2one("res.country", string="Country Manufacturer") |
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,26 +1,19 @@ | ||
<?xml version="1.0" ?> | ||
<odoo> | ||
<data> | ||
|
||
<record model="ir.ui.view" id="product_template_manufacturer_form_view"> | ||
<field name="name">product.product_template_form_view</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="product.product_template_form_view"/> | ||
<field name="arch" type="xml"> | ||
<page name="general_information" position="inside"> | ||
<group name="manufacturer" string="Manufacturer"> | ||
<group> | ||
<field name="manufacturer" context="{'default_supplier':True, 'default_customer':False}"/> | ||
<field name="manufacturer_pname" /> | ||
</group> | ||
<group> | ||
<field name="manufacturer_pref" /> | ||
<field name="manufacturer_purl" widget="url"/> | ||
</group> | ||
<record id="product_template_manufacturer_form_view" model="ir.ui.view"> | ||
<field name="name">product.template.form - product_manufacturer</field> | ||
<field name="model">product.template</field> | ||
<field name="inherit_id" ref="product.product_template_form_view"/> | ||
<field name="arch" type="xml"> | ||
<page name="general_information" position="inside"> | ||
<group name="manufacturer" string="Manufacturer"> | ||
<group> | ||
<field name="manufacturer" context="{'default_supplier':True, 'default_customer':False}"/> | ||
<field name="country_id"/> | ||
<field name="manufacturer_pname" /> | ||
</group> | ||
</page> | ||
</field> | ||
</record> | ||
|
||
</data> | ||
</group> | ||
</page> | ||
</field> | ||
</record> | ||
</odoo> |
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,22 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2004 Tiny SPRL | ||
# Copyright 2016 Sodexis | ||
# Copyright 2018 Eficent Business and IT Consulting Services S.L. | ||
# (http://www.eficent.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Product Sequence', | ||
'version': '10.0.1.0.0', | ||
'author': "Zikzakmedia SL,Sodexis,Odoo Community Association (OCA)", | ||
'website': 'http://www.zikzakmedia.com', | ||
'license': 'AGPL-3', | ||
'category': 'Generic Modules/Inventory Control', | ||
'depends': [ | ||
'product', | ||
], | ||
'data': [ | ||
'data/product_sequence.xml', | ||
], | ||
'pre_init_hook': 'pre_init_hook', | ||
'auto_install': False, | ||
'installable': True, | ||
"name": "Product Sequence", | ||
"version": "10.0.1.0.0", | ||
"author": "Zikzakmedia SL,Sodexis,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/product-attribute", | ||
"license": "AGPL-3", | ||
"category": "Product", | ||
"depends": ["product"], | ||
"data": ["data/product_sequence.xml", "views/product_category.xml"], | ||
"pre_init_hook": "pre_init_hook", | ||
"auto_install": False, | ||
"installable": True, | ||
} |
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,6 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2004 Tiny SPRL | ||
# Copyright 2016 Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import product_product | ||
from . import product_category |
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,92 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2018 Eficent Business and IT Consulting Services S.L. | ||
# (http://www.eficent.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models, fields, api | ||
|
||
|
||
class ProductCategory(models.Model): | ||
_inherit = "product.category" | ||
|
||
code_prefix = fields.Char( | ||
string="Prefix for Product Internal Reference", | ||
help="Prefix used to generate the internal reference for products " | ||
"created with this category. If blank the " | ||
"default sequence will be used.", | ||
company_dependent=True, | ||
) | ||
sequence_id = fields.Many2one( | ||
comodel_name="ir.sequence", | ||
string="Product Sequence", | ||
help="This field contains the information related to the numbering " | ||
"of the journal entries of this journal.", | ||
copy=False, | ||
readonly=True, | ||
) | ||
|
||
@api.model | ||
def _get_existing_sequence(self, prefix, company=False): | ||
"""Tries to find a valid sequence for the given prefix and company | ||
(optional) | ||
:param prefix: a string with the prefix of the sequence. | ||
:param company: a res.company record. | ||
:return: a single ir.sequence record or the empty model. | ||
""" | ||
domain = [("prefix", "=", prefix), ("code", "ilike", "product.product")] | ||
if company: | ||
domain.extend( | ||
["|", ("company_id", "=", company.id), ("company_id", "=", False)] | ||
) | ||
return self.env["ir.sequence"].search(domain, limit=1, order="company_id") | ||
|
||
@api.model | ||
def _prepare_ir_sequence(self, prefix, company=False): | ||
"""Prepare the vals for creating the sequence | ||
:param prefix: a string with the prefix of the sequence. | ||
:param company: a res.company record. | ||
:return: a dict with the values. | ||
""" | ||
vals = { | ||
"name": "Product " + prefix, | ||
"code": "product.product - " + prefix, | ||
"padding": 5, | ||
"prefix": prefix, | ||
} | ||
if company: | ||
vals["company_id"] = company.id | ||
return vals | ||
|
||
@api.model | ||
def _get_default_company(self): | ||
return self.env.user.company_id | ||
|
||
@api.multi | ||
def write(self, vals): | ||
prefix = vals.get("code_prefix") | ||
if prefix: | ||
sequence = self._get_existing_sequence( | ||
prefix, company=self._get_default_company() | ||
) | ||
if not sequence: | ||
seq_vals = self._prepare_ir_sequence( | ||
prefix, company=self._get_default_company() | ||
) | ||
sequence = self.env["ir.sequence"].create(seq_vals) | ||
vals["sequence_id"] = sequence.id | ||
return super(ProductCategory, self).write(vals) | ||
|
||
@api.model | ||
def create(self, vals): | ||
prefix = vals.get("code_prefix") | ||
if prefix: | ||
sequence = self._get_existing_sequence( | ||
prefix, company=self._get_default_company() | ||
) | ||
if not sequence: | ||
seq_vals = self._prepare_ir_sequence( | ||
prefix, company=self._get_default_company() | ||
) | ||
sequence = self.env["ir.sequence"].create(seq_vals) | ||
vals["sequence_id"] = sequence.id | ||
return super(ProductCategory, self).create(vals) |
Oops, something went wrong.