-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] sale_gathering_index: add new sale gathering module with index
- Loading branch information
Showing
8 changed files
with
335 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,70 @@ | ||
.. |company| replace:: ADHOC SA | ||
|
||
.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png | ||
:alt: ADHOC SA | ||
:target: https://www.adhoc.com.ar | ||
|
||
.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png | ||
|
||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png | ||
:target: https://www.gnu.org/licenses/agpl | ||
:alt: License: AGPL-3 | ||
|
||
==================== | ||
Sale Gathering Index | ||
==================== | ||
|
||
#. | ||
|
||
Installation | ||
============ | ||
|
||
To install this module, you need to: | ||
|
||
#. Only need to install the module. | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
#. Nothing to configure. | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Just use. | ||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: http://runbot.adhoc.com.ar/ | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/ingadhoc/sale/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. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* |company| |icon| | ||
|
||
Contributors | ||
------------ | ||
|
||
Maintainer | ||
---------- | ||
|
||
|company_logo| | ||
|
||
This module is maintained by the |company|. | ||
|
||
To contribute to this module, please visit https://www.adhoc.com.ar. |
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,5 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
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,42 @@ | ||
############################################################################## | ||
# | ||
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar) | ||
# All Rights Reserved. | ||
# | ||
# 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': 'Sale Gathering Index', | ||
'version': "16.0.1.0.0", | ||
'category': 'Sales & Stock', | ||
'sequence': 14, | ||
'summary': '', | ||
'author': 'ADHOC SA', | ||
'website': 'www.adhoc.com.ar', | ||
'license': 'AGPL-3', | ||
'images': [ | ||
], | ||
'depends': [ | ||
'sale_gathering' | ||
], | ||
'data': [ | ||
'views/sale_order_views.xml' | ||
], | ||
'demo': [ | ||
], | ||
'installable': True, | ||
'auto_install': False, | ||
'application': False, | ||
} |
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,62 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * sale_gathering_index | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 16.0+e\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2024-03-13 14:59+0000\n" | ||
"PO-Revision-Date: 2024-03-13 14:59+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: sale_gathering_index | ||
#: model:ir.model.fields,field_description:sale_gathering_index.field_sale_order__gathering_balance_indexed | ||
msgid "Gathering Balance Indexed" | ||
msgstr "Balance de acopio indexado" | ||
|
||
#. module: sale_gathering_index | ||
#: model:ir.model.fields,field_description:sale_gathering_index.field_sale_order__index | ||
msgid "Index" | ||
msgstr "Índice" | ||
|
||
#. module: sale_gathering_index | ||
#: model:ir.model,name:sale_gathering_index.model_sale_order | ||
msgid "Sales Order" | ||
msgstr "Pedido de venta" | ||
|
||
#. module: sale_gathering_index | ||
#: model:ir.model,name:sale_gathering_index.model_sale_order_line | ||
msgid "Sales Order Line" | ||
msgstr "Línea de pedido de venta" | ||
|
||
#. module: sale_gathering_index | ||
#: model:ir.model.fields,field_description:sale_gathering_index.field_sale_order__indexed_gathering_amount | ||
msgid "Indexed Gathering Amount" | ||
msgstr "Monto acopiado indexado" | ||
|
||
#. module: sale_gathering_index | ||
#. odoo-python | ||
#: code:addons/sale_gathering_index/models/sale_order_line.py:0 | ||
#, python-format | ||
msgid "" | ||
"You can't add an already gathered product more than once. Please modify the " | ||
"quantity of the existing line." | ||
msgstr "" | ||
"No puedes agregar un producto de acopio más de una vez. Por favor modifique " | ||
"el la cantidad de la línea existente." | ||
|
||
#. module: sale_gathering_index | ||
#. odoo-python | ||
#: code:addons/sale_gathering_index/models/sale_order_line.py:0 | ||
#, python-format | ||
msgid "" | ||
"You can't modify the quantity of an added product. Please add a new line." | ||
msgstr "" | ||
"No puedes modificar la cantidad de un producto agregado. Por favor agregar " | ||
"una nueva línea." |
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 @@ | ||
############################################################################## | ||
# For copyright and license notices, see __manifest__.py file in module root | ||
# directory | ||
############################################################################## | ||
from . import sale_order | ||
from . import sale_order_line |
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,65 @@ | ||
from odoo import models, fields, api | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
index = fields.Float('Index', compute="_compute_index") | ||
gathering_balance_indexed = fields.Float( | ||
compute="_compute_gathering_balance_indexed", | ||
digits='Product Price', | ||
help='Balance equivalente del acopio inicial actualizado por el indice de inflacion calculado en este acopio' | ||
) | ||
indexed_gathering_amount = fields.Float( | ||
compute="_compute_indexed_gathering_amount", | ||
digits='Product Price', | ||
help='Monto equivalente del acopio inicial actualizado por el indice de inflacion calculado en este acopio' | ||
) | ||
|
||
@api.depends('order_line.product_id.lst_price') | ||
def _compute_indexed_gathering_amount(self): | ||
gathering_orders = self.filtered( | ||
lambda x: x.is_gathering and x.order_line.filtered(lambda x: x.initial_qty_gathered > 0) | ||
) | ||
for order in gathering_orders: | ||
indexed_gathering_amount = 0.0 | ||
for line in order.order_line.filtered(lambda x: x.initial_qty_gathered > 0): | ||
price = line.with_company(line.company_id)._get_display_price() | ||
line_price = line.product_id._get_tax_included_unit_price( | ||
line.company_id, | ||
line.order_id.currency_id, | ||
line.order_id.date_order, | ||
'sale', | ||
fiscal_position=line.order_id.fiscal_position_id, | ||
product_price_unit=price, | ||
product_currency=line.currency_id | ||
) | ||
tax_results = self.env['account.tax']._compute_taxes( | ||
[self.env['account.tax']._convert_to_tax_base_line_dict( | ||
line, | ||
partner=line.order_id.partner_id, | ||
currency=line.order_id.currency_id, | ||
product=line.product_id, | ||
taxes=line.tax_id, | ||
price_unit=line_price, | ||
quantity=line.initial_qty_gathered, | ||
discount=line.discount, | ||
price_subtotal=line.price_subtotal, | ||
)]) | ||
totals = list(tax_results['totals'].values())[0] | ||
indexed_gathering_amount += totals['amount_untaxed'] | ||
order.indexed_gathering_amount = indexed_gathering_amount | ||
(self - gathering_orders).indexed_gathering_amount = 0.0 | ||
|
||
@api.depends('is_gathering', 'order_line.initial_qty_gathered', 'indexed_gathering_amount', 'amount') | ||
def _compute_index(self): | ||
gathering_orders = self.filtered( | ||
lambda x: x.is_gathering and x.order_line.filtered(lambda x: x.initial_qty_gathered > 0) | ||
) | ||
for order in gathering_orders: | ||
order.index = (order.indexed_gathering_amount / order.amount) - 1 | ||
(self - gathering_orders).index = 0.0 | ||
|
||
@api.depends('gathering_balance', 'index') | ||
def _compute_gathering_balance_indexed(self): | ||
self.gathering_balance_indexed = self.gathering_balance * (1 + self.index) |
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,51 @@ | ||
from odoo import models, api, _ | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class SaleOrderLine(models.Model): | ||
_inherit = 'sale.order.line' | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
order = self.env['sale.order'].browse(vals_list[0].get('order_id')) | ||
if order and order.is_gathering and order.state == 'sale': | ||
existing_product_ids = set(self.env['sale.order.line'].search([ | ||
('order_id', '=', order.id), | ||
('initial_qty_gathered', '>', 0) | ||
]).mapped('product_template_id.id')) | ||
new_product_ids = set(vals.get('product_template_id') for vals in vals_list) | ||
if existing_product_ids.intersection(new_product_ids): | ||
raise UserError(_("You can't add an already gathered product more than once. Please modify the quantity of the existing line.")) | ||
return super(SaleOrderLine, self).create(vals_list) | ||
|
||
def write(self, vals): | ||
if ( | ||
self.order_id.is_gathering | ||
and self.order_id.state == 'sale' | ||
and 'product_uom_qty' in vals | ||
and vals['product_uom_qty'] > self.product_uom_qty | ||
and 'initial_qty_gathered' not in vals | ||
and self.initial_qty_gathered == 0 | ||
): | ||
raise UserError(_("You can't modify the quantity of an added product. Please add a new line.")) | ||
return super(SaleOrderLine, self).write(vals) | ||
|
||
def _compute_price_unit(self): | ||
super()._compute_price_unit() | ||
for rec in self.filtered(lambda x: x.order_id.is_gathering and x.order_id.state == 'sale' and x.initial_qty_gathered == 0): | ||
rec.price_unit = rec.price_unit / (rec.order_id.index + 1) | ||
|
||
def _compute_name(self): | ||
super()._compute_name() | ||
for line in self.filtered(lambda x: x.order_id.is_gathering and x.order_id.state == 'sale' and x.initial_qty_gathered == 0 and not x.display_type and not x.is_downpayment and x.name): | ||
price = line.with_company(line.company_id)._get_display_price() | ||
line_price = line.product_id._get_tax_included_unit_price( | ||
line.company_id, | ||
line.order_id.currency_id, | ||
line.order_id.date_order, | ||
'sale', | ||
fiscal_position=line.order_id.fiscal_position_id, | ||
product_price_unit=price, | ||
product_currency=line.currency_id | ||
) | ||
line.name += "\n($%s)\n(%s%%)" % (line_price, round(line.order_id.index*100, 2)) |
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,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<record id="view_order_form" model="ir.ui.view"> | ||
<field name="name">sale.order.form</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="payment_term_id" position="after"> | ||
<field name="index" attrs="{'invisible': [('is_gathering', '=', False)]}" widget="percentage"/> | ||
</field> | ||
<xpath expr="//field[@name='order_line']/tree//field[@name='name']" position="attributes"> | ||
<attribute name="attrs">{'readonly': [('parent.is_gathering', '=', True), ('display_type', 'not in', ['line_section', 'line_note'])]}</attribute> | ||
</xpath> | ||
<xpath expr="//field[@name='order_line']/tree//field[@name='price_unit']" position="attributes"> | ||
<attribute name="attrs">{'readonly': [('parent.is_gathering', '=', True), ('state', '=', 'sale')]}</attribute> | ||
</xpath> | ||
<group name="sale_total" position="inside"> | ||
<field name="indexed_gathering_amount" widget="monetary" options="{'currency_field': 'currency_id'}" attrs="{'invisible': [('is_gathering', '=', False)]}"/> | ||
<field name="gathering_balance_indexed" widget="monetary" options="{'currency_field': 'currency_id'}" attrs="{'invisible': [('is_gathering', '=', False)]}"/> | ||
</group> | ||
</field> | ||
</record> | ||
|
||
<record id="view_order_tree" model="ir.ui.view"> | ||
<field name="name">sale.order.tree</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_tree"/> | ||
<field name="arch" type="xml"> | ||
<field name="state" position="before"> | ||
<field name="index" widget="percentage"/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |