forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] module base_product_mass_addition
- Loading branch information
1 parent
e0131db
commit 4d0a98c
Showing
13 changed files
with
715 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
========================== | ||
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 | ||
~~~~~~~~~~~~ | ||
|
||
* Sébastien BEAU <[email protected]> | ||
* Mourad EL HADJ MIMOUNE <[email protected]> | ||
* Pierrick Brun <[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,20 @@ | ||
# coding: utf-8 | ||
# © 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, | ||
} |
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 product_product |
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 @@ | ||
# © 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 | ||
from odoo.tests.common import Form | ||
|
||
|
||
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 _prepare_quick_line(self, parent): | ||
res = self._get_quick_line_qty_vals() | ||
res.update({'product_id': self.id}) | ||
return res | ||
|
||
def _get_quick_line(self, parent): | ||
raise NotImplementedError | ||
|
||
def _add_quick_line(self, parent, line_model): | ||
vals = self._prepare_quick_line(parent) | ||
vals = self._complete_quick_line_vals(False, vals) | ||
if not vals.get('price_unit'): | ||
vals['price_unit'] = 0.0 | ||
self.env[line_model].create(vals) | ||
|
||
def _update_quick_line(self, line): | ||
if self.qty_to_process: | ||
# apply the on change to update price unit if depends on qty | ||
vals = self._get_quick_line_qty_vals() | ||
vals = self._complete_quick_line_vals(line, vals) | ||
line.write(vals) | ||
else: | ||
line.unlink() | ||
|
||
def _get_quick_line_qty_vals(self): | ||
raise NotImplementedError | ||
|
||
def _complete_quick_line_vals(self, line, vals, view=False, parent_key=''): | ||
if not view: | ||
raise NotImplementedError | ||
form_line = None | ||
if line: | ||
form_line = Form(line, view=view['ref']) | ||
else: | ||
form_line = Form(self.env[view['model']], view=view['ref']) | ||
init_keys = ['product_id', parent_key] | ||
init_vals = [(key, val) for key, val in vals.items() | ||
if key in init_keys] | ||
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 | ||
|
||
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 = self._get_quick_line(parent) | ||
if quick_line: | ||
product._update_quick_line(quick_line) | ||
else: | ||
product._add_quick_line(parent, quick_line._name) | ||
|
||
def _compute_process_qty(self): | ||
if not self.env.context.get('parent_id'): | ||
return | ||
|
||
@api.multi | ||
def button_return_parent(self): | ||
self.ensure_one() | ||
parent_id = self.env.context.get('parent_id') | ||
parent_model = self.env.context.get('parent_model') | ||
if parent_id: | ||
parent = self.env[parent_model].browse(parent_id) | ||
return { | ||
'name': parent.display_name, | ||
'type': 'ir.actions.act_window', | ||
'res_model': parent_model, | ||
'view_mode': 'form', | ||
'res_id': parent_id, | ||
} |
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,3 @@ | ||
* Sébastien BEAU <[email protected]> | ||
* Mourad EL HADJ MIMOUNE <[email protected]> | ||
* Pierrick Brun <[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.