Skip to content

Commit f33b275

Browse files
robinkeunencarmenbianca
authored andcommitted
[ADD] purchase_invoice_new_picking_line
1 parent be201aa commit f33b275

File tree

10 files changed

+651
-0
lines changed

10 files changed

+651
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
=================================
2+
Purchase Invoice New Picking Line
3+
=================================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
15+
:alt: License: AGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-oca%2Fpurchase--workflow-lightgray.png?logo=github
17+
:target: https://github.com/oca/purchase-workflow/tree/12.0/purchase_invoice_new_picking_line
18+
:alt: oca/purchase-workflow
19+
20+
|badge1| |badge2| |badge3|
21+
22+
When creating an invoice from incoming picking,
23+
this module also adds invoice lines for product
24+
that were not in the purchase order.
25+
26+
**Table of contents**
27+
28+
.. contents::
29+
:local:
30+
31+
Bug Tracker
32+
===========
33+
34+
Bugs are tracked on `GitHub Issues <https://github.com/oca/purchase-workflow/issues>`_.
35+
In case of trouble, please check there if your issue has already been reported.
36+
If you spotted it first, help us smashing it by providing a detailed and welcomed
37+
`feedback <https://github.com/oca/purchase-workflow/issues/new?body=module:%20purchase_invoice_new_picking_line%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
38+
39+
Do not contact contributors directly about support or help with technical issues.
40+
41+
Credits
42+
=======
43+
44+
Authors
45+
~~~~~~~
46+
47+
* Coop IT Easy SCRLfs
48+
49+
Contributors
50+
~~~~~~~~~~~~
51+
52+
* Robin Keunen <[email protected]>
53+
54+
Maintainers
55+
~~~~~~~~~~~
56+
57+
This module is part of the `oca/purchase-workflow <https://github.com/oca/purchase-workflow/tree/12.0/purchase_invoice_new_picking_line>`_ project on GitHub.
58+
59+
You are welcome to contribute.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2020 Coop IT Easy SCRLfs
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
4+
{
5+
"name": "Purchase Invoice New Picking Line",
6+
"summary": "When creating an invoice from incoming picking, also adds invoice lines for product that were not in the purchase order",
7+
"version": "12.0.1.0.0",
8+
"author": "Coop IT Easy SCRLfs, " "Odoo Community Association (OCA)",
9+
"category": "Purchase",
10+
"license": "AGPL-3",
11+
"website": "https://github.com/OCA/purchase-workflow",
12+
"depends": ["purchase_stock"],
13+
"installable": True,
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import account_invoice
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2020 Coop IT Easy SCRL fs
2+
# Robin Keunen <[email protected]>
3+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
4+
5+
from odoo import api, models
6+
from odoo.tools.float_utils import float_compare
7+
8+
9+
class AccountInvoice(models.Model):
10+
_inherit = "account.invoice"
11+
12+
@api.multi
13+
def _get_move_account_id(self, move):
14+
self.ensure_one()
15+
invoice_line_obj = self.env["account.invoice.line"]
16+
account = invoice_line_obj.get_invoice_line_account(
17+
"in_invoice",
18+
move.product_id,
19+
self.partner_id.property_account_position_id,
20+
self.env.user.company_id,
21+
)
22+
if account:
23+
account_id = account.id
24+
else:
25+
account_id = invoice_line_obj.with_context(
26+
{"journal_id": self.journal_id.id, "type": "in_invoice"}
27+
)._default_account()
28+
return account_id
29+
30+
@api.multi
31+
def _prepare_invoice_line_from_move(self, move):
32+
self.ensure_one()
33+
qty = move.quantity_done
34+
flt_comparison = float_compare(
35+
qty, 0.0, precision_rounding=move.product_uom.rounding
36+
)
37+
if flt_comparison <= 0:
38+
qty = 0.0
39+
40+
taxes = move.product_id.supplier_taxes_id
41+
invoice_line_tax_ids = self.env["account.fiscal.position"].map_tax(
42+
taxes, move.product_id, self.partner_id
43+
) # fixme not sure about this
44+
account_id = self._get_move_account_id(move)
45+
data = {
46+
"name": move.name,
47+
"origin": self.origin,
48+
"uom_id": move.product_uom.id,
49+
"product_id": move.product_id.id,
50+
"account_id": account_id,
51+
"price_unit": move.price_unit,
52+
"quantity": qty,
53+
"discount": 0.0,
54+
# fixme not sure what to do with this
55+
# "account_analytic_id": move.account_analytic_id.id,
56+
# "analytic_tag_ids": move.analytic_tag_ids.ids,
57+
"invoice_line_tax_ids": invoice_line_tax_ids.ids,
58+
}
59+
60+
return data
61+
62+
@api.onchange("purchase_id")
63+
def purchase_order_change(self):
64+
res = super(AccountInvoice, self).purchase_order_change()
65+
po = self.env["purchase.order"].search([("name", "=", self.origin)])
66+
moves = po.picking_ids.filtered(
67+
lambda p: p.state == "done"
68+
).move_ids_without_package
69+
moves_to_invoice = moves.filtered(
70+
lambda m: m.state == "done" and not m.purchase_line_id
71+
)
72+
new_lines = self.env["account.invoice.line"]
73+
for move in moves_to_invoice:
74+
data = self._prepare_invoice_line_from_move(move)
75+
new_line = new_lines.new(data)
76+
new_line._set_additional_fields(self)
77+
new_lines += new_line
78+
79+
self.invoice_line_ids += new_lines
80+
return res
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Robin Keunen <[email protected]>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
When creating an invoice from incoming picking,
2+
this module also adds invoice lines for product
3+
that were not in the purchase order.

0 commit comments

Comments
 (0)