forked from OCA/purchase-workflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD]purchase_workflow: puchase_invoice_line_zero module added
- Loading branch information
Showing
5 changed files
with
87 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 @@ | ||
Purchase Line Invoice Line Zero |
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 @@ | ||
# Copyright 2023, Jarsa | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
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,15 @@ | ||
# © 2023 Jarsa | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Purchase Invoice Line Zero", | ||
"version": "15.0.1.0.0", | ||
"category": "Hidden", | ||
"website": "https://www.jarsa.com.mx/", | ||
"author": "Jarsa", | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"purchase", | ||
], | ||
"installable": True, | ||
} |
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 @@ | ||
# Copyright 2023, Jarsa | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
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,63 @@ | ||
# Copyright 2020, Jarsa Sistemas, S.A. de C.V. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
||
from odoo import api, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
def _get_invoice_reference(self): | ||
# OVERRIDE | ||
self.ensure_one() | ||
vendor_refs = [ref for ref in set(self.line_ids.mapped("purchase_line_id.order_id.name")) if ref] | ||
if self.ref: | ||
return [ref for ref in self.ref.split(", ") if ref and ref not in vendor_refs] + vendor_refs | ||
return vendor_refs | ||
|
||
# Load all unsold PO lines | ||
@api.onchange("purchase_vendor_bill_id", "purchase_id") | ||
def _onchange_purchase_auto_complete(self): | ||
# OVERRIDE | ||
purchase_vendor_bill = self.purchase_vendor_bill_id.vendor_bill_id | ||
if purchase_vendor_bill: | ||
self.invoice_vendor_bill_id = purchase_vendor_bill | ||
self._onchange_invoice_vendor_bill() | ||
elif self.purchase_vendor_bill_id.purchase_order_id: | ||
self.purchase_id = self.purchase_vendor_bill_id.purchase_order_id | ||
self.purchase_vendor_bill_id = False | ||
|
||
if not self.purchase_id: | ||
return | ||
|
||
# Copy partner. | ||
self.partner_id = self.purchase_id.partner_id | ||
self.fiscal_position_id = self.purchase_id.fiscal_position_id | ||
self.invoice_payment_term_id = self.purchase_id.payment_term_id | ||
self.currency_id = self.purchase_id.currency_id | ||
self.company_id = self.purchase_id.company_id | ||
|
||
# Copy purchase lines. | ||
po_lines = self.purchase_id.order_line - self.line_ids.mapped("purchase_line_id") | ||
new_lines = self.env["account.move.line"] | ||
for line in po_lines.filtered(lambda l: not l.display_type and l.qty_received - l.qty_invoiced > 0): | ||
new_line = new_lines.new(line._prepare_account_move_line(self)) | ||
new_line.account_id = new_line._get_computed_account() | ||
new_line._onchange_price_subtotal() | ||
new_lines += new_line | ||
new_lines._onchange_mark_recompute_taxes() | ||
|
||
# Compute invoice_origin. | ||
origins = set(self.line_ids.mapped("purchase_line_id.order_id.name")) | ||
self.invoice_origin = ",".join(list(origins)) | ||
|
||
# Compute ref. | ||
refs = self._get_invoice_reference() | ||
self.ref = ", ".join(refs) | ||
|
||
# Compute invoice_payment_ref. | ||
if len(refs) == 1: | ||
self.invoice_payment_ref = refs[0] | ||
|
||
self.purchase_id = False |