forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from OCA/12.0
Syncing from upstream OCA/product-attribute (12.0)
- Loading branch information
Showing
19 changed files
with
826 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
========================== | ||
Base Product Mass Addition | ||
========================== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github | ||
:target: https://github.com/OCA/product-attribute/tree/12.0/base_product_mass_addition | ||
:alt: OCA/product-attribute | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/product-attribute-12-0/product-attribute-12-0-base_product_mass_addition | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/135/12.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module is abstract and can't be used as is. | ||
|
||
It provides functions in order to show a product grid from another model. | ||
You can then add products and quantities in batch to the model you are working with. | ||
|
||
It is useful when you don't want to add every product line possible to your object. | ||
From the product grid you only have to set the quantity for each product. | ||
|
||
Example implementations: | ||
- purchase_quick | ||
- stock_picking_quick | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
The module uses Form emulation from backend. | ||
Once onchange_helper is stabilized, we should switch to it | ||
because it is more robust and has better perfs. | ||
|
||
Also adding new implementations would be great: | ||
on sale.order or on stock.picking.batch for instance. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20base_product_mass_addition%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Akretion | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
Akretion | ||
|
||
* Sébastien BEAU <[email protected]> | ||
* Mourad EL HADJ MIMOUNE <[email protected]> | ||
* Pierrick Brun <[email protected]> | ||
* David Béal <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
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. | ||
|
||
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/12.0/base_product_mass_addition>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 @@ | ||
from . import models |
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,19 @@ | ||
# © 2019 Today Akretion | ||
# @author Pierrick Brun <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
'name': 'Base Product Mass Addition', | ||
'version': '12.0.1.0.0', | ||
'author': 'Akretion, Odoo Community Association (OCA)', | ||
'website': 'https://github.com/OCA/product-attribute', | ||
'license': 'AGPL-3', | ||
'category': 'Product', | ||
'depends': [ | ||
'stock', | ||
], | ||
'data': [ | ||
'views/product_view.xml', | ||
], | ||
'installable': True, | ||
} |
70 changes: 70 additions & 0 deletions
70
base_product_mass_addition/i18n/base_product_mass_addition.pot
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,70 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * base_product_mass_addition | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 12.0\n" | ||
"Report-Msgid-Bugs-To: \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: base_product_mass_addition | ||
#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_mass_addition__display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view | ||
msgid "Filter products in current parent" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_mass_addition__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view | ||
msgid "In current parent" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_mass_addition____last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_product_tree_view | ||
msgid "Open" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model:ir.model,name:base_product_mass_addition.model_product_product | ||
msgid "Product" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_product_tree_view | ||
msgid "Products" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__qty_to_process | ||
msgid "Qty To Process" | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__qty_to_process | ||
msgid "Set this quantity to create a new line for this product or update the existing one." | ||
msgstr "" | ||
|
||
#. module: base_product_mass_addition | ||
#: model:ir.model,name:base_product_mass_addition.model_product_mass_addition | ||
msgid "inherit this to add a mass product addition function to your model" | ||
msgstr "" | ||
|
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,2 @@ | ||
from . import product_product | ||
from . import product_mass_addition |
79 changes: 79 additions & 0 deletions
79
base_product_mass_addition/models/product_mass_addition.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,79 @@ | ||
# © 2019 Today Akretion | ||
# @author Pierrick Brun <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
||
from odoo import models, api | ||
from odoo.tests.common import Form | ||
|
||
|
||
class ProductMassAddition(models.AbstractModel): | ||
_name = 'product.mass.addition' | ||
_description = 'inherit this to add a mass product addition function\ | ||
to your model' | ||
|
||
@api.model | ||
def _common_action_keys(self): | ||
""" Call it in your own child module | ||
""" | ||
return { | ||
'type': 'ir.actions.act_window', | ||
'res_model': 'product.product', | ||
'target': 'current', | ||
'context': {'parent_id': self.id, 'parent_model': self._name}, | ||
'view_mode': 'tree', | ||
} | ||
|
||
def _prepare_quick_line(self, product): | ||
res = self._get_quick_line_qty_vals(product) | ||
res.update({'product_id': product.id}) | ||
return res | ||
|
||
def _get_quick_line(self, product): | ||
raise NotImplementedError | ||
|
||
def _add_quick_line(self, product, lines_key=''): | ||
if not lines_key: | ||
raise NotImplementedError | ||
vals = self._prepare_quick_line(product) | ||
vals = self._complete_quick_line_vals(vals) | ||
self.write({lines_key: [(0, 0, vals)]}) | ||
|
||
def _update_quick_line(self, product, line): | ||
if product.qty_to_process: | ||
# apply the on change to update price unit if depends on qty | ||
vals = self._get_quick_line_qty_vals(product) | ||
vals['id'] = line.id | ||
vals = self._complete_quick_line_vals(vals) | ||
line.write(vals) | ||
else: | ||
line.unlink() | ||
|
||
def _get_quick_line_qty_vals(self, product): | ||
raise NotImplementedError | ||
|
||
def _complete_quick_line_vals(self, vals, lines_key=''): | ||
if not lines_key: | ||
raise NotImplementedError | ||
form_parent = Form(self) | ||
form_line = False | ||
if vals.get('id'): | ||
for index, line in enumerate(self[lines_key]): | ||
if line.id == vals.get('id'): | ||
form_line = getattr(form_parent, lines_key).edit(index) | ||
del vals['id'] | ||
break | ||
init_keys = ['product_id'] | ||
init_vals = [(key, val) for key, val in vals.items() | ||
if key in init_keys] | ||
if not form_line: | ||
form_line = getattr(form_parent, lines_key).new() | ||
form_line._values.update(init_vals) | ||
form_line._perform_onchange(init_keys) | ||
|
||
update_keys = [key for key in vals.keys() if key not in init_keys] | ||
update_vals = [(key, val) for key, val in vals.items() | ||
if key not in init_keys] | ||
form_line._values.update(update_vals) | ||
form_line._perform_onchange(update_keys) | ||
return form_line._values |
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,47 @@ | ||
# © 2014 Today Akretion | ||
# @author Sébastien BEAU <[email protected]> | ||
# @author Mourad EL HADJ MIMOUNE <[email protected]> | ||
# @author Pierrick Brun <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = 'product.product' | ||
|
||
qty_to_process = fields.Float( | ||
compute='_compute_process_qty', | ||
inverse='_inverse_set_process_qty', | ||
help="Set this quantity to create a new line " | ||
"for this product or update the existing one." | ||
) | ||
|
||
def _inverse_set_process_qty(self): | ||
parent_model = self.env.context.get('parent_model') | ||
parent_id = self.env.context.get('parent_id') | ||
if parent_model: | ||
parent = self.env[parent_model].browse(parent_id) | ||
for product in self: | ||
quick_line = parent._get_quick_line(product) | ||
if quick_line: | ||
parent._update_quick_line(product, quick_line) | ||
else: | ||
parent._add_quick_line(product, quick_line._name) | ||
|
||
def _compute_process_qty(self): | ||
if not self.env.context.get('parent_id'): | ||
return | ||
|
||
@api.multi | ||
def button_quick_open_product(self): | ||
self.ensure_one() | ||
return { | ||
'name': self.display_name, | ||
'type': 'ir.actions.act_window', | ||
'res_model': self._name, | ||
'view_mode': 'form', | ||
'res_id': self.id, | ||
'target': 'current', | ||
} |
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,6 @@ | ||
Akretion | ||
|
||
* Sébastien BEAU <[email protected]> | ||
* Mourad EL HADJ MIMOUNE <[email protected]> | ||
* Pierrick Brun <[email protected]> | ||
* David Béal <[email protected]> |
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,11 @@ | ||
This module is abstract and can't be used as is. | ||
|
||
It provides functions in order to show a product grid from another model. | ||
You can then add products and quantities in batch to the model you are working with. | ||
|
||
It is useful when you don't want to add every product line possible to your object. | ||
From the product grid you only have to set the quantity for each product. | ||
|
||
Example implementations: | ||
- purchase_quick | ||
- stock_picking_quick |
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,6 @@ | ||
The module uses Form emulation from backend. | ||
Once onchange_helper is stabilized, we should switch to it | ||
because it is more robust and has better perfs. | ||
|
||
Also adding new implementations would be great: | ||
on sale.order or on stock.picking.batch for instance. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.