Skip to content

Commit

Permalink
[ADD] account_move_stock_create: new addon
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoParadeda committed Oct 29, 2024
1 parent c746bc2 commit 3d44e62
Show file tree
Hide file tree
Showing 14 changed files with 690 additions and 0 deletions.
89 changes: 89 additions & 0 deletions account_move_stock_create/README.rst
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.
1 change: 1 addition & 0 deletions account_move_stock_create/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions account_move_stock_create/__manifest__.py
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": [],
}
1 change: 1 addition & 0 deletions account_move_stock_create/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_move
100 changes: 100 additions & 0 deletions account_move_stock_create/models/account_move.py
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(

Check warning on line 24 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L24

Added line #L24 was not covered by tests
_("There's already a picking created for this account move.")
)
elif record.picking_ids:
continue
record.generate_picking_from_invoice()

Check warning on line 29 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L28-L29

Added lines #L28 - L29 were not covered by tests

def generate_picking_from_invoice(self):
"""Generate a picking from the invoice."""
self.ensure_one()

Check warning on line 33 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L33

Added line #L33 was not covered by tests
if self.move_type not in INVOICE_TYPE_MAP:
raise UserError(f"Unsupported move type: {self.move_type}")

Check warning on line 35 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L35

Added line #L35 was not covered by tests

picking_type_code, location_src_usage, location_dest_usage = INVOICE_TYPE_MAP[

Check warning on line 37 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L37

Added line #L37 was not covered by tests
self.move_type
]

# Picking type
picking_type_id = self.env["stock.picking.type"].search(

Check warning on line 42 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L42

Added line #L42 was not covered by tests
[("code", "=", picking_type_code)],
limit=1,
)

# Locations
location_src_id = self.env["stock.location"].search(

Check warning on line 48 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L48

Added line #L48 was not covered by tests
[("usage", "=", location_src_usage)],
limit=1,
)
location_dest_id = self.env["stock.location"].search(

Check warning on line 52 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L52

Added line #L52 was not covered by tests
[("usage", "=", location_dest_usage)],
limit=1,
)

# Picking
picking_values = {

Check warning on line 58 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L58

Added line #L58 was not covered by tests
"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)

Check warning on line 74 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L74

Added line #L74 was not covered by tests

def _prepare_stock_move_values(self, invoice_line, picking_values):
"""Prepare stock move values from invoice line."""
self.ensure_one()
return {

Check warning on line 79 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L78-L79

Added lines #L78 - L79 were not covered by tests
"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)

Check warning on line 100 in account_move_stock_create/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_move_stock_create/models/account_move.py#L100

Added line #L100 was not covered by tests
1 change: 1 addition & 0 deletions account_move_stock_create/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Diego Paradeda <diego.paradeda@kmee.com.br>
1 change: 1 addition & 0 deletions account_move_stock_create/readme/DESCRIPTION.rst
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.
1 change: 1 addition & 0 deletions account_move_stock_create/readme/INSTALL.rst
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)
4 changes: 4 additions & 0 deletions account_move_stock_create/readme/USAGE.rst
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.
Loading

0 comments on commit 3d44e62

Please sign in to comment.