Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] add setup for stock_picking_return_refund_option_setup #2

Open
wants to merge 12 commits into
base: 13.0-mig-stock_picking_return_refund_option
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions setup/stock_picking_return_refund_option/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
140 changes: 140 additions & 0 deletions stock_picking_return_refund_option/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
==================================
Stock Picking Return Refund Option
==================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |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%2Faccount--invoicing-lightgray.png?logo=github
:target: https://github.com/OCA/account-invoicing/tree/13.0/stock_picking_return_refund_option
:alt: OCA/account-invoicing
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-invoicing-13-0/account-invoicing-13-0-stock_picking_return_refund_option
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/95/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of sales and purchase orders to support
modify stock move field to_refund after it has been confirmed.

**Table of contents**

.. contents::
:local:

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

#. This module requires the additional installation of sale_stock or purchase
modules for enabling the features it contains.

Usage
=====

To use this module, when some customer returns some refundable products to you
after you created an invoice, you need to:

For a sale order:

#. Go to *Sales > Sales Orders > Create*.
#. Choose a customer and add a product whose *Invoicing Policy* is *Delivered
quantities*, and input some quantity to sell.
#. Confirm the sale.
#. Go to *Delivery > Validate > Apply*.
#. Return to the sale order.
#. Press *Create Invoice > Invoiceable lines > Create and View Invoices*.
#. The created invoice's amount is the same you sold.
#. Return to the sale order.
#. Go to *Delivery > Return*.
#. Set *Quantity* to a lower quantity than the sold one, and enable
*To Refund*.
#. Press *Return > Validate > Apply*.
#. Return to the sale order.
#. Press *Create Invoice > Invoiceable lines (deduct down payments) >
Create and View Invoices*.
#. A refund is created for the quantity you returned before.

For allowing to refund quantities after the picking has been confirmed if you
did not check 'to refund' in wizard, you can change the value
of 'Refund Options' field.

To use this module, when you return some refundable products to your supplier
after you created an invoice, you need to:

#. Go to *Purchase > Purchase Orders > Create*.
#. Choose a supplier and add a product whose *Invoicing Policy* is *Delivered
quantities*, and input some quantity to buy.
#. Confirm the order.
#. Go to *Delivery > Validate > Apply*.
#. Return to the purchase order.
#. Press on smart button "Invoices" and create one.
#. The created invoice's amount is the same you sold.
#. Return to the purchase order.
#. Go to *Delivery > Return*.
#. Set *Quantity* to a lower quantity than you bought, and enable
*To Refund*.
#. Press *Return > Validate > Apply*.
#. Return to the purchase order.

For allowing to refund quantities after the picking has been confirmed if you
did not check 'to refund' in wizard, you can change the value
of 'Refund Options' field.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/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/account-invoicing/issues/new?body=module:%20stock_picking_return_refund_option%0Aversion:%2013.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
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* Sergio Teruel <[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.

.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px
:target: https://github.com/sergio-teruel
:alt: sergio-teruel

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sergio-teruel|

This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/13.0/stock_picking_return_refund_option>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 4 additions & 0 deletions stock_picking_return_refund_option/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from .hooks import pre_init_hook
from . import models
18 changes: 18 additions & 0 deletions stock_picking_return_refund_option/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock Picking Return Refund Option",
"summary": "Update the refund options in pickings",
"version": "13.0.1.0.0",
"development_status": "Production/Stable",
"category": "Sales",
"website": "https://github.com/OCA/account-invoicing",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["stock_account"],
"data": ["views/stock_picking_view.xml"],
"pre_init_hook": "pre_init_hook",
"maintainers": ["sergio-teruel"],
}
18 changes: 18 additions & 0 deletions stock_picking_return_refund_option/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api, tools


def pre_init_hook(cr):
if not tools.config.options.get("without_demo", False):
env = api.Environment(cr, SUPERUSER_ID, {})
modules = env["ir.module.module"].search(
[
("name", "in", ["purchase_stock", "sale_stock"]),
("state", "!=", "installed"),
]
)
modules_dep = modules.upstream_dependencies(
exclude_states=("installed", "uninstallable", "to remove")
)
(modules_dep + modules).write({"state": "to install"})
68 changes: 68 additions & 0 deletions stock_picking_return_refund_option/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_return_refund_option
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-12-04 17:16+0000\n"
"PO-Revision-Date: 2019-12-04 18:17+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es_ES\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.0.6\n"

#. module: stock_picking_return_refund_option
#: model:ir.model.fields,field_description:stock_picking_return_refund_option.field_stock_picking__is_return
msgid "Is Return"
msgstr "Es devolución"

#. module: stock_picking_return_refund_option
#: selection:stock.picking,to_refund_lines:0
msgid "No Refund"
msgstr "No abonar"

#. module: stock_picking_return_refund_option
#: model:ir.model.fields,field_description:stock_picking_return_refund_option.field_stock_picking__to_refund_lines
#: model_terms:ir.ui.view,arch_db:stock_picking_return_refund_option.view_picking_form
msgid "Refund Options"
msgstr "Opciones de devolución"

#. module: stock_picking_return_refund_option
#: model:ir.model.fields,help:stock_picking_return_refund_option.field_stock_picking__to_refund_lines
msgid ""
"This field allow modify 'to_refund' field value in all stock moves from this "
"picking after it has been confirmed.to_refund: set all stock moves to True "
"value and recompute delivered quantities in sale order.\n"
"no_refund: set all stock moves to False value and recompute delivered "
"quantities in sale/purchase order."
msgstr ""
"Este campo permite modificar el valor del campo 'para abonar en el pedido' "
"de todos los movimientos de stock del albarán después de que haya sido "
"confirmado.\n"
"Para abonar en el pedido: Actualiza todos los movimientos de stock con el "
"valor a 'verdadero' y recalcula las unidades entregadas del pedido de "
"venta.\n"
"No abonar en el pedido: Actualiza todos los movimientos de stock con el "
"valor a 'falso' y recalcula las unidades entregadas del pedido de venta."

#. module: stock_picking_return_refund_option
#: selection:stock.picking,to_refund_lines:0
msgid "To Refund"
msgstr "Para abonar"

#. module: stock_picking_return_refund_option
#: model:ir.model,name:stock_picking_return_refund_option.model_stock_picking
msgid "Transfer"
msgstr "Transferir"

#~ msgid "Return Picking"
#~ msgstr "Albarán de devolución"

#~ msgid "Stock Move"
#~ msgstr "Movimiento de stock"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_return_refund_option
#
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: stock_picking_return_refund_option
#: model:ir.model.fields,field_description:stock_picking_return_refund_option.field_stock_picking__is_return
msgid "Is Return"
msgstr ""

#. module: stock_picking_return_refund_option
#: selection:stock.picking,to_refund_lines:0
msgid "No Refund"
msgstr ""

#. module: stock_picking_return_refund_option
#: model:ir.model.fields,field_description:stock_picking_return_refund_option.field_stock_picking__to_refund_lines
#: model_terms:ir.ui.view,arch_db:stock_picking_return_refund_option.view_picking_form
msgid "Refund Options"
msgstr ""

#. module: stock_picking_return_refund_option
#: model:ir.model.fields,help:stock_picking_return_refund_option.field_stock_picking__to_refund_lines
msgid "This field allow modify 'to_refund' field value in all stock moves from this picking after it has been confirmed.to_refund: set all stock moves to True value and recompute delivered quantities in sale order.\n"
"no_refund: set all stock moves to False value and recompute delivered quantities in sale/purchase order."
msgstr ""

#. module: stock_picking_return_refund_option
#: selection:stock.picking,to_refund_lines:0
msgid "To Refund"
msgstr ""

#. module: stock_picking_return_refund_option
#: model:ir.model,name:stock_picking_return_refund_option.model_stock_picking
msgid "Transfer"
msgstr ""

2 changes: 2 additions & 0 deletions stock_picking_return_refund_option/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import stock_picking
81 changes: 81 additions & 0 deletions stock_picking_return_refund_option/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class StockPicking(models.Model):
_inherit = "stock.picking"

to_refund_lines = fields.Selection(
selection=[("to_refund", "To Refund"), ("no_refund", "No Refund")],
compute="_compute_to_refund_lines",
inverse="_inverse_to_refund_lines",
string="Refund Options",
help="This field allow modify 'to_refund' field value in all "
"stock moves from this picking after it has been confirmed."
"to_refund: set all stock moves to True value and recompute "
"delivered quantities in sale order.\n"
"no_refund: set all stock moves to False value and recompute "
"delivered quantities in sale/purchase order.",
)
is_return = fields.Boolean(compute="_compute_is_return")

@api.depends("move_lines.to_refund")
def _compute_to_refund_lines(self):
for picking in self:
moves_to_refund = picking.move_lines.filtered(lambda mv: mv.to_refund)
if not moves_to_refund:
picking.to_refund_lines = "no_refund"
elif len(moves_to_refund) == len(picking.move_lines):
picking.to_refund_lines = "to_refund"
else:
picking.to_refund_lines = False

def _inverse_to_refund_lines(self):
"""
Set to_refund stock_move field:
All lines to True.
All lines to False.
Each line to original value selected in return wizard by user.
"""
for picking in self:
picking._update_stock_moves()
picking.set_delivered_qty()
picking.set_received_qty()

def _compute_is_return(self):
for picking in self:
if any(x.origin_returned_move_id for x in picking.move_lines):
picking.is_return = True
else:
picking.is_return = False

def _update_stock_moves(self):
for pick in self.filtered("to_refund_lines"):
pick.move_lines.write({"to_refund": pick.to_refund_lines == "to_refund"})

def set_delivered_qty(self):
"""
Check if exists sale_line_id field in stock.move model that has been
added by sale_stock module, this module has not dependency of this,
Update sale order line qty_delivered for allow do a refund invoice
"""
if hasattr(self.env["stock.move"], "sale_line_id") and self.sale_id:
# The sale_stock module is installed
so_lines = self.mapped("move_lines.sale_line_id").filtered(
lambda x: x.product_id.invoice_policy in ("order", "delivery")
)
so_lines._compute_qty_delivered()

def set_received_qty(self):
"""
Check if exists purchase_line_id field in stock.move model that has
been added by purchase module, this module has not dependency of this,
Update purchase order line qty_received for allow do a refund invoice.
"""
if hasattr(self.env["stock.move"], "purchase_line_id") and self.purchase_id:
# The purchase module is installed
po_lines = self.mapped("move_lines.purchase_line_id").filtered(
lambda x: x.product_id.invoice_policy in ("order", "delivery")
)
po_lines._compute_qty_received()
1 change: 1 addition & 0 deletions stock_picking_return_refund_option/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sergio Teruel <[email protected]>
Loading