-
-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] account_move_stock_create: new addon
- Loading branch information
1 parent
c746bc2
commit 3d44e62
Showing
14 changed files
with
690 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,89 @@ | ||
========================= | ||
Account Move Stock Create | ||
========================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:d6d4854666e5badaa6d03f574dd80462df7efbed75f3b700eddbba2277927b10 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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%2Faccount--invoicing-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account-invoicing/tree/14.0/account_move_stock_create | ||
: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-14-0/account-invoicing-14-0-account_move_stock_create | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=14.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module enables the creation of stock transfers directly from invoices, streamlining the inventory update process and ensuring alignment between sales and stock levels. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Installation | ||
============ | ||
|
||
This module depends on stock_picking_invoice_link. You can find it at [OCA/stock-logistics-workflow](https://github.com/OCA/stock-logistics-workflow) | ||
|
||
Usage | ||
===== | ||
|
||
#. Go to *Invoices* then either *Customer > Invoices* or *Vendor > Bills*. | ||
#. Select one invoice or bill.. | ||
#. Click on *Action > Create Stock Picking*. | ||
#. Pickings are linked to invoices using *stock_picking_invoice_link* from [OCA/stock-logistics-workflow](https://github.com/OCA/stock-logistics-workflow) | ||
|
||
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 to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_move_stock_create%0Aversion:%2014.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 | ||
~~~~~~~ | ||
|
||
* KMEE INFORMATICA LTDA | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Diego Paradeda <diego.paradeda@kmee.com.br> | ||
|
||
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/account-invoicing <https://github.com/OCA/account-invoicing/tree/14.0/account_move_stock_create>`_ 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,21 @@ | ||
# Copyright (C) 2024-Today - KMEE (<http://www.kmee.com.br>). | ||
# @author Diego Paradeda <diego.paradeda@kmee.com.br> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Account Move Stock Create", | ||
"summary": """This addon creates stock transfers from an account move""", | ||
"version": "14.0.1.0.0", | ||
"license": "AGPL-3", | ||
"author": "KMEE INFORMATICA LTDA,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/account-invoicing", | ||
"depends": [ | ||
"stock", | ||
"account", | ||
"stock_picking_invoice_link", | ||
], | ||
"data": [ | ||
"views/account_move_views.xml", | ||
], | ||
"demo": [], | ||
} |
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 account_move |
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,100 @@ | ||
# Copyright (C) 2024-Today - KMEE (<http://www.kmee.com.br>). | ||
# Author: Diego Paradeda <diego.paradeda@kmee.com.br> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import _, models | ||
from odoo.exceptions import UserError | ||
|
||
INVOICE_TYPE_MAP = { | ||
# Account Move Type | Picking Type Code | Local Origin Usage | Local Dest Usage | ||
"in_invoice": ("incoming", "supplier", "internal"), | ||
"in_refund": ("outgoing", "internal", "supplier"), | ||
"out_invoice": ("outgoing", "internal", "customer"), | ||
"out_refund": ("incoming", "customer", "internal"), | ||
} | ||
|
||
|
||
class AccountInvoice(models.Model): | ||
_inherit = "account.move" | ||
|
||
def action_generate_pickings_from_invoices(self): | ||
"""Generate pickings from invoices.""" | ||
for record in self: | ||
if record.picking_ids and len(self) == 1: | ||
raise UserError( | ||
_("There's already a picking created for this account move.") | ||
) | ||
elif record.picking_ids: | ||
continue | ||
record.generate_picking_from_invoice() | ||
|
||
def generate_picking_from_invoice(self): | ||
"""Generate a picking from the invoice.""" | ||
self.ensure_one() | ||
if self.move_type not in INVOICE_TYPE_MAP: | ||
raise UserError(f"Unsupported move type: {self.move_type}") | ||
|
||
picking_type_code, location_src_usage, location_dest_usage = INVOICE_TYPE_MAP[ | ||
self.move_type | ||
] | ||
|
||
# Picking type | ||
picking_type_id = self.env["stock.picking.type"].search( | ||
[("code", "=", picking_type_code)], | ||
limit=1, | ||
) | ||
|
||
# Locations | ||
location_src_id = self.env["stock.location"].search( | ||
[("usage", "=", location_src_usage)], | ||
limit=1, | ||
) | ||
location_dest_id = self.env["stock.location"].search( | ||
[("usage", "=", location_dest_usage)], | ||
limit=1, | ||
) | ||
|
||
# Picking | ||
picking_values = { | ||
"partner_id": self.partner_id.id, | ||
"picking_type_id": picking_type_id.id, | ||
"location_id": location_src_id.id, | ||
"location_dest_id": location_dest_id.id, | ||
"invoice_ids": self.ids, | ||
"origin": self.name, | ||
} | ||
|
||
# Moves | ||
move_values = [ | ||
self._prepare_stock_move_values(line, picking_values) | ||
for line in self.invoice_line_ids | ||
] | ||
picking_values["move_lines"] = [(0, 0, move) for move in move_values] | ||
|
||
self._create_picking(picking_values=picking_values) | ||
|
||
def _prepare_stock_move_values(self, invoice_line, picking_values): | ||
"""Prepare stock move values from invoice line.""" | ||
self.ensure_one() | ||
return { | ||
"name": invoice_line.product_id.name, | ||
"product_id": invoice_line.product_id.id, | ||
"location_id": picking_values.get("location_id"), | ||
"location_dest_id": picking_values.get("location_dest_id"), | ||
"state": "draft", | ||
"company_id": self.company_id.id, | ||
"product_uom_qty": invoice_line.quantity, | ||
"product_uom": invoice_line.product_uom_id.id, | ||
"invoice_line_ids": invoice_line.ids, | ||
} | ||
|
||
def _create_picking(self, picking_values): | ||
"""Create a picking with the given values. | ||
Override this method if you need to change any values of the | ||
picking and the lines before the picking creation. | ||
:param picking_values: dict with the picking and its lines | ||
:return: picking | ||
""" | ||
return self.env["stock.picking"].create(picking_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 @@ | ||
* Diego Paradeda <diego.paradeda@kmee.com.br> |
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 @@ | ||
This module enables the creation of stock transfers directly from invoices, streamlining the inventory update process and ensuring alignment between sales and stock levels. |
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 @@ | ||
This module depends on stock_picking_invoice_link. You can find it at [OCA/stock-logistics-workflow](https://github.com/OCA/stock-logistics-workflow) |
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,4 @@ | ||
#. Go to *Invoices* then either *Customer > Invoices* or *Vendor > Bills*. | ||
#. Select one invoice or bill.. | ||
#. Click on *Action > Create Stock Picking*. | ||
#. Pickings are linked to invoices using *stock_picking_invoice_link* from [OCA/stock-logistics-workflow](https://github.com/OCA/stock-logistics-workflow) |
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.