Skip to content

Commit

Permalink
Merge c944b0c into f4a33d0
Browse files Browse the repository at this point in the history
  • Loading branch information
ovnicraft committed May 27, 2019
2 parents f4a33d0 + c944b0c commit ffa4f0b
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 110 deletions.
41 changes: 41 additions & 0 deletions product_manufacturer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,47 @@ A module that adds manufacturers and attributes on the product form.
You can now define the following for a product:
-----------------------------------------------
* Manufacturer
* Country Manufacture
* Manufacturer Product Name
* Manufacturer Product Code
* Manufacturer Product URL

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.

Contributors
------------

* Odoo S.A.
* Acysos SL <info@acysos.com>
* Ray Carnes <ray.carnes@bistasolutions.com>
* Miquel Raïch <miquel.raich@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
* Cristian Salamea <cs@prisehub.com>

Do not contact contributors directly about support or help with technical issues.

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
23 changes: 10 additions & 13 deletions product_manufacturer/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
#
##############################################################################
{
'name': 'Product Manufacturers',
'version': '10.0.1.0.0',
'author': "OpenERP SA, Odoo Community Association (OCA)",
'license': 'AGPL-3',
'contributors': ['Acysos SL <info@acysos.com>'],
'category': 'Purchase Management',
'depends': ['product'],
'demo': [],
'data': [
'views/product_manufacturer_view.xml'
],
'auto_install': False,
'installable': True,
"name": "Product Manufacturer",
"version": "10.0.1.1.0",
"summary": "Adds manufacturers and attributes on the product view.",
"author": "OpenERP SA, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Product",
"depends": ["product"],
"data": ["views/product_manufacturer_view.xml"],
"auto_install": False,
"installable": True,
}
32 changes: 7 additions & 25 deletions product_manufacturer/models/product_manufacturer.py
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")
37 changes: 15 additions & 22 deletions product_manufacturer/views/product_manufacturer_view.xml
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>
23 changes: 19 additions & 4 deletions product_sequence/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,31 @@ Product Sequence
This module allows to associate a sequence to the product reference.
The reference (default code) is unique (SQL constraint) and required.

You can optionally specify different sequences for different product
categories.

Installation
============

Prior to installing this module, if you have any existing products you should ensure
they already have a unique reference (or no reference) set. Products with a default_code of
'/' or empty will automatically be assigned a code of "!!mig!!" followed by the system id for that product.
Prior to installing this module, if you have any existing products you should
ensure they already have a unique reference (or no reference) set. Products
with a default_code of '/' or empty will automatically be assigned a code of
"!!mig!!" followed by the system id for that product.

Otherwise the setting of the unique constraint will fail and the module will fail to install.
Otherwise the setting of the unique constraint will fail and the module will
fail to install.

Usage
=====

To specify a different sequence for a product category proceed as follows:

#. Go to the a Product Category form view.
(**note:** you will need to install Inventory app to be able to access to
the form view, *Inventory > Configuration > Products > Products Categories*;
or create a menuitem manually).
#. Fill the *Prefix for Product Internal Reference* as desired.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/135/10.0
Expand All @@ -47,6 +60,8 @@ Contributors
* Angel Moya <angel.moya@domatix.com>
* Graeme Gellatly <g@o4sb.com>
* Sodexis <dev@sodexis.com>
* Lois Rilo <lois.rilo@eficent.com>
* Cristian Salamea <cs@prisehub.com>

Maintainer
----------
Expand Down
3 changes: 0 additions & 3 deletions product_sequence/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2004 Tiny SPRL
# Copyright 2016 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
Expand Down
28 changes: 13 additions & 15 deletions product_sequence/__manifest__.py
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,
}
8 changes: 5 additions & 3 deletions product_sequence/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def pre_init_hook(cr):
:param cr: database cursor
:return: void
"""
cr.execute("UPDATE product_product "
"SET default_code = '!!mig!!' || id "
"WHERE default_code IS NULL OR default_code = '/';")
cr.execute(
"UPDATE product_product "
"SET default_code = '!!mig!!' || id "
"WHERE default_code IS NULL OR default_code = '/';"
)
4 changes: 1 addition & 3 deletions product_sequence/models/__init__.py
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
92 changes: 92 additions & 0 deletions product_sequence/models/product_category.py
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)

0 comments on commit ffa4f0b

Please sign in to comment.