-
-
Notifications
You must be signed in to change notification settings - Fork 688
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] account_move_stock_create: new addon #1827
base: 14.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 <[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/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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
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 <[email protected]> | ||
# 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": [], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import account_move |
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 <[email protected]> | ||
# 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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is common to have more than one picking grouped in the same invoice... But also more generally, I think it would be cool to have a wizard or maybe an o2m field were one could select existing pickings. If so, the module could try to match the existing stock moves with some kind of key (product_id, possibly quantity...) and simply link matched stock moves, possibly with some match flag that would visually show what was matched or not. If the line could not be matched, then it might be generated as you did... It is indeed common that PO will generate incoming pickings that one will mostly want to match when electronic invoices are imported. With your current proposals you would need to delete manually these incoming pickings generated from the PO's and your PO will miss their delivery and invoicing status... Bonus, it should be flexible so that it will keep working with the new PO/Bill matching system from v18. |
||
|
||
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) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Diego Paradeda <[email protected]> |
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. |
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) |
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KMEE only plz.