Browse Source
Merge pull request #20 from akretion/8.0-pos-product-category
Merge pull request #20 from akretion/8.0-pos-product-category
[ADD] Add 'pos_product_category' modulepull/25/head
Sylvain LE GAL
10 years ago
11 changed files with 366 additions and 1 deletions
-
1.gitignore
-
48pos_remove_pos_category/README.rst
-
23pos_remove_pos_category/__init__.py
-
38pos_remove_pos_category/__openerp__.py
-
22pos_remove_pos_category/i18n/fr.po
-
22pos_remove_pos_category/i18n/pos_remove_pos_category.pot
-
70pos_remove_pos_category/module.py
-
19pos_remove_pos_category/point_of_sale_view.xml
-
79pos_remove_pos_category/product.py
-
35pos_remove_pos_category/static/src/js/pos_remove_pos_category.js
-
10pos_remove_pos_category/views/pos_remove_pos_category.xml
@ -0,0 +1,48 @@ |
|||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
|||
:alt: License |
|||
|
|||
POS Remove POS Category |
|||
======================= |
|||
|
|||
This module was written to replace POS categories by product categories |
|||
in the point of sale. |
|||
|
|||
Important notes |
|||
--------------- |
|||
- When the module is installed the link beetween products and POS categories |
|||
is **overwritten** by a link beetween products and product categories |
|||
(the link is the field pos_categ_id in the table product_template) |
|||
- When the module is uninstalled the link beetween products and POS categories |
|||
is restored in an **empty** state (NULL values) |
|||
|
|||
Installation |
|||
============ |
|||
|
|||
This module depends on the `point_of_sale` Odoo official module. |
|||
|
|||
Configuration |
|||
============= |
|||
|
|||
No configuration is needed just use product categories as standard |
|||
pos categories. |
|||
|
|||
Credits |
|||
======= |
|||
|
|||
Contributors |
|||
------------ |
|||
|
|||
* Sylvain Calador <sylvain.calador@akretion.com> |
|||
|
|||
Maintainer |
|||
---------- |
|||
|
|||
.. image:: http://odoo-community.org/logo.png |
|||
:alt: Odoo Community Association |
|||
:target: http://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 http://odoo-community.org. |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>). |
|||
# |
|||
# 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 . import product |
|||
from . import module |
@ -0,0 +1,38 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>). |
|||
# |
|||
# 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/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
{ |
|||
'name': 'POS Remove POS Category', |
|||
'version': '0.1', |
|||
'author': 'Akretion, Odoo Community Association (OCA)', |
|||
'category': 'Sales Management', |
|||
'depends': [ |
|||
'point_of_sale', |
|||
], |
|||
'demo': [], |
|||
'website': 'https://www.akretion.com', |
|||
'data': [ |
|||
'point_of_sale_view.xml', |
|||
'views/pos_remove_pos_category.xml', |
|||
], |
|||
'installable': True, |
|||
'auto_install': False, |
|||
} |
@ -0,0 +1,22 @@ |
|||
# Translation of Odoo Server. |
|||
# This file contains the translation of the following modules: |
|||
# * pos_remove_pos_category |
|||
# |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: Odoo Server 8.0\n" |
|||
"Report-Msgid-Bugs-To: \n" |
|||
"POT-Creation-Date: 2015-03-31 09:05+0000\n" |
|||
"PO-Revision-Date: 2015-03-31 09:05+0000\n" |
|||
"Last-Translator: <>\n" |
|||
"Language-Team: \n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=UTF-8\n" |
|||
"Content-Transfer-Encoding: \n" |
|||
"Plural-Forms: \n" |
|||
|
|||
#. module: pos_remove_pos_category |
|||
#: model:ir.model,name:pos_remove_pos_category.model_product_template |
|||
msgid "Product Template" |
|||
msgstr "Modèle d'article" |
|||
|
@ -0,0 +1,22 @@ |
|||
# Translation of Odoo Server. |
|||
# This file contains the translation of the following modules: |
|||
# * pos_remove_pos_category |
|||
# |
|||
msgid "" |
|||
msgstr "" |
|||
"Project-Id-Version: Odoo Server 8.0\n" |
|||
"Report-Msgid-Bugs-To: \n" |
|||
"POT-Creation-Date: 2015-03-31 09:01+0000\n" |
|||
"PO-Revision-Date: 2015-03-31 09:01+0000\n" |
|||
"Last-Translator: <>\n" |
|||
"Language-Team: \n" |
|||
"MIME-Version: 1.0\n" |
|||
"Content-Type: text/plain; charset=UTF-8\n" |
|||
"Content-Transfer-Encoding: \n" |
|||
"Plural-Forms: \n" |
|||
|
|||
#. module: pos_remove_pos_category |
|||
#: model:ir.model,name:pos_remove_pos_category.model_product_template |
|||
msgid "Product Template" |
|||
msgstr "" |
|||
|
@ -0,0 +1,70 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>). |
|||
# |
|||
# 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 |
|||
|
|||
|
|||
class Module(models.Model): |
|||
|
|||
_inherit = 'ir.module.module' |
|||
|
|||
def module_uninstall(self, cr, uid, ids, context=None): |
|||
|
|||
context = context or {} |
|||
|
|||
for module in self.browse(cr, uid, ids, context=context): |
|||
if module.name == 'pos_remove_pos_category': |
|||
|
|||
# As we have loose previous POS categs restore them |
|||
# in a sane empty state |
|||
|
|||
cr.execute('UPDATE product_template SET pos_categ_id=NULL') |
|||
|
|||
# And restore original constraint |
|||
cr.execute(''' |
|||
ALTER TABLE product_template |
|||
DROP CONSTRAINT IF EXISTS |
|||
product_template_pos_categ_id_fkey |
|||
''') |
|||
|
|||
cr.execute(''' |
|||
ALTER TABLE product_template ADD CONSTRAINT |
|||
"product_template_pos_categ_id_fkey" |
|||
FOREIGN KEY (pos_categ_id) |
|||
REFERENCES pos_category(id) ON DELETE SET NULL; |
|||
''') |
|||
|
|||
# Restore POS category menu action |
|||
# in SQL because pool/env is not available here |
|||
cr.execute(''' |
|||
UPDATE ir_act_window iaw SET res_model='pos.category' |
|||
FROM ir_model_data imd |
|||
WHERE |
|||
iaw.id = imd.res_id AND |
|||
imd.model = 'ir.actions.act_window' AND |
|||
imd.name = 'product_pos_category_action' |
|||
''') |
|||
|
|||
break |
|||
|
|||
return super(Module, self).module_uninstall( |
|||
cr, uid, ids, context=context |
|||
) |
@ -0,0 +1,19 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<openerp> |
|||
<data> |
|||
<record id="product_template_form_view" model="ir.ui.view"> |
|||
<field name="name">product.template.form.inherit</field> |
|||
<field name="model">product.template</field> |
|||
<field name="inherit_id" ref="product.product_template_form_view"/> |
|||
<field name="priority" eval="100"/> |
|||
<field name="arch" type="xml"> |
|||
<field name="pos_categ_id" position="attributes"> |
|||
<attribute name="invisible">1</attribute> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
<record id="point_of_sale.product_pos_category_action" model="ir.actions.act_window"> |
|||
<field name="res_model">product.category</field> |
|||
</record> |
|||
</data> |
|||
</openerp> |
@ -0,0 +1,79 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# OpenERP, Open Source Management Solution |
|||
# Copyright (C) 2015-TODAY Akretion (<http://www.akretion.com>). |
|||
# |
|||
# 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/>. |
|||
# |
|||
############################################################################## |
|||
|
|||
import sys |
|||
from openerp import models, fields, api |
|||
|
|||
|
|||
class ProductTemplate(models.Model): |
|||
_inherit = 'product.template' |
|||
|
|||
pos_categ_id = fields.Many2one('product.category', |
|||
store=True, related='categ_id') |
|||
|
|||
@api.model |
|||
def create(self, vals): |
|||
vals['pos_categ_id'] = vals['categ_id'] |
|||
return super(ProductTemplate, self).create(vals) |
|||
|
|||
@api.multi |
|||
def write(self, vals): |
|||
if 'pos_categ_id' in vals and not vals['pos_categ_id']: |
|||
del vals['pos_categ_id'] |
|||
return super(ProductTemplate, self).write(vals) |
|||
|
|||
|
|||
_auto_end_original = models.BaseModel._auto_end |
|||
|
|||
|
|||
def _auto_end(self, cr, context=None): |
|||
""" Create the foreign keys recorded by _auto_init. |
|||
(pos_remove_pos_category monkey patching) |
|||
""" |
|||
context = context or {} |
|||
module = context['module'] |
|||
foreign_keys = [] |
|||
patched = 'openerp.addons.pos_remove_pos_category' in sys.modules |
|||
|
|||
for t, k, r, d in self._foreign_keys: |
|||
if patched and (t, k) == ('product_template', 'pos_categ_id'): |
|||
if module == 'pos_remove_pos_category': |
|||
cr.execute(''' |
|||
ALTER TABLE product_template |
|||
DROP CONSTRAINT IF EXISTS |
|||
product_template_pos_categ_id_fkey |
|||
''') |
|||
cr.execute(''' |
|||
UPDATE product_template |
|||
SET pos_categ_id = categ_id; |
|||
''') |
|||
cr.execute(''' |
|||
ALTER TABLE product_template ADD CONSTRAINT |
|||
"product_template_pos_categ_id_fkey" |
|||
FOREIGN KEY (pos_categ_id) |
|||
REFERENCES product_category(id) ON DELETE SET NULL; |
|||
''') |
|||
continue |
|||
foreign_keys.append((t, k, r, d)) |
|||
self._foreign_keys = foreign_keys |
|||
return _auto_end_original(self, cr, context=context) |
|||
|
|||
models.BaseModel._auto_end = _auto_end |
@ -0,0 +1,35 @@ |
|||
/****************************************************************************** |
|||
* Point Of Sale - Pricelist for POS Odoo |
|||
* Copyright (C) 2015-TODAY Akretion (http://www.akretion.com)
|
|||
* @author Sylvain Calador <sylvain.calador@akretion.com> |
|||
* |
|||
* 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/>.
|
|||
* |
|||
******************************************************************************/ |
|||
|
|||
openerp.pos_remove_pos_category = function(instance, local) { |
|||
module = instance.point_of_sale; |
|||
|
|||
var initialize_original = module.PosModel.prototype.initialize; |
|||
module.PosModel = module.PosModel.extend({ |
|||
|
|||
initialize: function(session, attributes) { |
|||
|
|||
for (var i = 0 ; i < this.models.length; i++){ |
|||
if (this.models[i].model == 'pos.category') { |
|||
this.models[i].model = 'product.category'; |
|||
} |
|||
} |
|||
return initialize_original.call(this, session, attributes); |
|||
} |
|||
}); |
|||
}; |
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<openerp> |
|||
<data> |
|||
<template id="assets_backend" name="pos_remove_pos_category assets" inherit_id="web.assets_backend"> |
|||
<xpath expr="." position="inside"> |
|||
<script type="text/javascript" src="/pos_remove_pos_category/static/src/js/pos_remove_pos_category.js"></script> |
|||
</xpath> |
|||
</template> |
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue