Skip to content

Commit ad651a6

Browse files
[ADD] account_invoice_purchase_picking_selection: New module to auto-complete invoice lines from picking originating from a purchase order.
1 parent eedfa02 commit ad651a6

File tree

18 files changed

+1563
-0
lines changed

18 files changed

+1563
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
==============================================
2+
Autocomplete purchase invoices from receptions
3+
==============================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:622e17d9ae10d521496c54ff6f310cb6f7fe675c6c2a6eb44e727fb379c85849
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--invoicing-lightgray.png?logo=github
20+
:target: https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_purchase_picking_selection
21+
:alt: OCA/account-invoicing
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/account-invoicing-14-0/account-invoicing-14-0-account_invoice_purchase_picking_selection
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/account-invoicing&target_branch=14.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
Autocomplete invoices lines by selecting the receptions originating from a purchase order.
32+
33+
**Table of contents**
34+
35+
.. contents::
36+
:local:
37+
38+
Usage
39+
=====
40+
41+
- Create some storable products and set the `Control Policy` to `On received quantities`.
42+
- Create a purchase order with the previously created storable products.
43+
- Confirm the purchase order
44+
- Receive the products
45+
- Go to `Invoicing > Vendors > Bills`
46+
- Create a new bill
47+
- Select the picking in the `Auto-Complete from Picking` field
48+
- The invoice lines will be automatically filled with the product quantities from the picking.
49+
50+
Bug Tracker
51+
===========
52+
53+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-invoicing/issues>`_.
54+
In case of trouble, please check there if your issue has already been reported.
55+
If you spotted it first, help us to smash it by providing a detailed and welcomed
56+
`feedback <https://github.com/OCA/account-invoicing/issues/new?body=module:%20account_invoice_purchase_picking_selection%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
57+
58+
Do not contact contributors directly about support or help with technical issues.
59+
60+
Credits
61+
=======
62+
63+
Authors
64+
~~~~~~~
65+
66+
* Tecnativa
67+
68+
Contributors
69+
~~~~~~~~~~~~
70+
71+
* `Tecnativa <https://www.tecnativa.com>`_
72+
73+
* Pedro M. Baeza
74+
* Carlos Lopez
75+
76+
77+
Maintainers
78+
~~~~~~~~~~~
79+
80+
This module is maintained by the OCA.
81+
82+
.. image:: https://odoo-community.org/logo.png
83+
:alt: Odoo Community Association
84+
:target: https://odoo-community.org
85+
86+
OCA, or the Odoo Community Association, is a nonprofit organization whose
87+
mission is to support the collaborative development of Odoo features and
88+
promote its widespread use.
89+
90+
This module is part of the `OCA/account-invoicing <https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_purchase_picking_selection>`_ project on GitHub.
91+
92+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Autocomplete purchase invoices from receptions",
3+
"version": "14.0.1.0.0",
4+
"summary": "Autocomplete invoices lines "
5+
"by selecting the receptions originating from a purchase order.",
6+
"author": "Tecnativa, Odoo Community Association (OCA)",
7+
"website": "https://github.com/OCA/account-invoicing",
8+
"category": "Inventory/Purchase",
9+
"depends": [
10+
"purchase_stock",
11+
],
12+
"data": ["views/account_move_views.xml"],
13+
"installable": True,
14+
"license": "AGPL-3",
15+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * account_invoice_purchase_picking_selection
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 14.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2025-03-19 15:27+0000\n"
10+
"PO-Revision-Date: 2025-03-19 15:27+0000\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: account_invoice_purchase_picking_selection
19+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_bank_statement_line__autocomplete_purchase_picking_id
20+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move__autocomplete_purchase_picking_id
21+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_payment__autocomplete_purchase_picking_id
22+
msgid "Auto-Complete from Picking"
23+
msgstr ""
24+
25+
#. module: account_invoice_purchase_picking_selection
26+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move__display_name
27+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move_line__display_name
28+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_stock_picking__display_name
29+
msgid "Display Name"
30+
msgstr ""
31+
32+
#. module: account_invoice_purchase_picking_selection
33+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move__id
34+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move_line__id
35+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_stock_picking__id
36+
msgid "ID"
37+
msgstr ""
38+
39+
#. module: account_invoice_purchase_picking_selection
40+
#: model:ir.model,name:account_invoice_purchase_picking_selection.model_account_move
41+
msgid "Journal Entry"
42+
msgstr ""
43+
44+
#. module: account_invoice_purchase_picking_selection
45+
#: model:ir.model,name:account_invoice_purchase_picking_selection.model_account_move_line
46+
msgid "Journal Item"
47+
msgstr ""
48+
49+
#. module: account_invoice_purchase_picking_selection
50+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move____last_update
51+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move_line____last_update
52+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_stock_picking____last_update
53+
msgid "Last Modified on"
54+
msgstr ""
55+
56+
#. module: account_invoice_purchase_picking_selection
57+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move_line__picking_invoiced_id
58+
msgid "Picking"
59+
msgstr ""
60+
61+
#. module: account_invoice_purchase_picking_selection
62+
#: model_terms:ir.ui.view,arch_db:account_invoice_purchase_picking_selection.view_account_move_form
63+
msgid "Select a purchase reception"
64+
msgstr ""
65+
66+
#. module: account_invoice_purchase_picking_selection
67+
#: model:ir.model,name:account_invoice_purchase_picking_selection.model_stock_picking
68+
msgid "Transfer"
69+
msgstr ""
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * account_invoice_purchase_picking_selection
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 14.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2025-03-19 15:27+0000\n"
10+
"PO-Revision-Date: 2025-03-19 10:28-0500\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"Language: es\n"
14+
"MIME-Version: 1.0\n"
15+
"Content-Type: text/plain; charset=UTF-8\n"
16+
"Content-Transfer-Encoding: 8bit\n"
17+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
18+
"X-Generator: Poedit 3.5\n"
19+
20+
#. module: account_invoice_purchase_picking_selection
21+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_bank_statement_line__autocomplete_purchase_picking_id
22+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move__autocomplete_purchase_picking_id
23+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_payment__autocomplete_purchase_picking_id
24+
msgid "Auto-Complete from Picking"
25+
msgstr "Completar automáticamente desde albarán"
26+
27+
#. module: account_invoice_purchase_picking_selection
28+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move__display_name
29+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move_line__display_name
30+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_stock_picking__display_name
31+
msgid "Display Name"
32+
msgstr "Nombre mostrado"
33+
34+
#. module: account_invoice_purchase_picking_selection
35+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move__id
36+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move_line__id
37+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_stock_picking__id
38+
msgid "ID"
39+
msgstr ""
40+
41+
#. module: account_invoice_purchase_picking_selection
42+
#: model:ir.model,name:account_invoice_purchase_picking_selection.model_account_move
43+
msgid "Journal Entry"
44+
msgstr "Asiento contable"
45+
46+
#. module: account_invoice_purchase_picking_selection
47+
#: model:ir.model,name:account_invoice_purchase_picking_selection.model_account_move_line
48+
msgid "Journal Item"
49+
msgstr "Apunte contable"
50+
51+
#. module: account_invoice_purchase_picking_selection
52+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move____last_update
53+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move_line____last_update
54+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_stock_picking____last_update
55+
msgid "Last Modified on"
56+
msgstr "Última modificación el"
57+
58+
#. module: account_invoice_purchase_picking_selection
59+
#: model:ir.model.fields,field_description:account_invoice_purchase_picking_selection.field_account_move_line__picking_invoiced_id
60+
msgid "Picking"
61+
msgstr "Albarán"
62+
63+
#. module: account_invoice_purchase_picking_selection
64+
#: model_terms:ir.ui.view,arch_db:account_invoice_purchase_picking_selection.view_account_move_form
65+
msgid "Select a purchase reception"
66+
msgstr "Seleccione una recepción de compra"
67+
68+
#. module: account_invoice_purchase_picking_selection
69+
#: model:ir.model,name:account_invoice_purchase_picking_selection.model_stock_picking
70+
msgid "Transfer"
71+
msgstr "Albarán"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from . import account_move
2+
from . import stock_picking
3+
from . import stock_move
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from odoo import api, fields, models
2+
from odoo.tools.float_utils import float_is_zero
3+
4+
5+
class AccountMove(models.Model):
6+
_inherit = "account.move"
7+
8+
autocomplete_purchase_picking_id = fields.Many2one(
9+
"stock.picking", copy=False, string="Auto-Complete from Picking"
10+
)
11+
12+
@api.onchange("autocomplete_purchase_picking_id")
13+
def _onchange_autocomplete_purchase_picking_id(self):
14+
"""Load from either an stock.picking."""
15+
if (
16+
not self.autocomplete_purchase_picking_id
17+
or not self.autocomplete_purchase_picking_id.purchase_id
18+
):
19+
return
20+
21+
# Copy data from PO
22+
purchase = self.autocomplete_purchase_picking_id.purchase_id
23+
stock_moves = self.autocomplete_purchase_picking_id.move_lines
24+
invoice_vals = purchase.with_company(purchase.company_id)._prepare_invoice()
25+
invoice_vals["currency_id"] = (
26+
self.line_ids and self.currency_id or invoice_vals.get("currency_id")
27+
)
28+
del invoice_vals["ref"]
29+
self.update(invoice_vals)
30+
31+
# Copy purchase lines.
32+
stock_moves -= self.line_ids.mapped("stock_move_invoiced_id")
33+
new_lines = self.env["account.move.line"]
34+
sequence = max(self.line_ids.mapped("sequence")) + 1 if self.line_ids else 10
35+
precision = self.env["decimal.precision"].precision_get(
36+
"Product Unit of Measure"
37+
)
38+
for stock_move in stock_moves:
39+
if float_is_zero(
40+
stock_move.qty_received_to_invoice, precision_digits=precision
41+
):
42+
continue
43+
line_vals = stock_move._prepare_account_move_line_from_stock(self, sequence)
44+
new_line = new_lines.new(line_vals)
45+
sequence += 1
46+
new_line.account_id = new_line._get_computed_account()
47+
new_line._onchange_price_subtotal()
48+
new_lines += new_line
49+
new_lines._onchange_mark_recompute_taxes()
50+
new_lines.picking_invoiced_id = self.autocomplete_purchase_picking_id
51+
52+
# Compute invoice_origin.
53+
origins = set(self.line_ids.mapped("purchase_line_id.order_id.name"))
54+
self.invoice_origin = ",".join(list(origins))
55+
56+
# Compute ref.
57+
refs = self._get_invoice_reference()
58+
self.ref = ", ".join(refs)
59+
60+
# Compute payment_reference.
61+
if len(refs) == 1:
62+
self.payment_reference = refs[0]
63+
64+
self.autocomplete_purchase_picking_id = False
65+
self.purchase_id = False
66+
self._onchange_currency()
67+
68+
69+
class AccountMoveLine(models.Model):
70+
_inherit = "account.move.line"
71+
72+
stock_move_invoiced_id = fields.Many2one(
73+
"stock.move", string="Stock Move", copy=False, readonly=True
74+
)
75+
picking_invoiced_id = fields.Many2one(
76+
"stock.picking", string="Picking", copy=False, readonly=True
77+
)

0 commit comments

Comments
 (0)