mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[13.0][ADD] stock_account_prepare_anglo_saxon_out_lines_hook
This commit is contained in:
63
stock_account_prepare_anglo_saxon_out_lines_hook/README.rst
Normal file
63
stock_account_prepare_anglo_saxon_out_lines_hook/README.rst
Normal file
@@ -0,0 +1,63 @@
|
||||
.. image:: https://img.shields.io/badge/license-AGPLv3-blue.svg
|
||||
:target: https://www.gnu.org/licenses/agpl.html
|
||||
:alt: License: AGPL-3
|
||||
|
||||
=============================
|
||||
Account Move Anglo Saxon Hook
|
||||
=============================
|
||||
|
||||
This module introduces a hook that allows to customize the criteria why
|
||||
anglosaxon entries for COGS are created
|
||||
|
||||
Standard Odoo will not create those entries for Kits where those are
|
||||
consumables. But they should be considered because of the interim output
|
||||
account is hit in the invoice.
|
||||
|
||||
References: https://github.com/odoo/odoo/issues/60679
|
||||
Proposal to Odoo: https://github.com/odoo/odoo/pull/68511
|
||||
|
||||
It also introduces a hook in order to add/modify the values on the
|
||||
anglo saxon journal entries creation. For example, the sales order information
|
||||
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/92/11.0
|
||||
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/account-financial-tools/issues>`_. In case of trouble, please
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Images
|
||||
------
|
||||
|
||||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Aaron Henriquez <ahenriquez@forgeflow.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
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.
|
||||
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
||||
@@ -0,0 +1,4 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import models
|
||||
from .hooks import post_load_hook
|
||||
@@ -0,0 +1,15 @@
|
||||
# Copyright 2020 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "Stock Account Prepare Anglo Saxon Oout Lines Hook",
|
||||
"summary": "Modify when and how anglo saxon journal items are created",
|
||||
"version": "13.0.1.0.0",
|
||||
"author": "ForgeFlow, Odoo Community Association (OCA)",
|
||||
"website": "http://www.github.com/OCA/account-financial-tools",
|
||||
"category": "Generic",
|
||||
"depends": ["stock_account"],
|
||||
"post_load": "post_load_hook",
|
||||
"license": "AGPL-3",
|
||||
"installable": True,
|
||||
}
|
||||
67
stock_account_prepare_anglo_saxon_out_lines_hook/hooks.py
Normal file
67
stock_account_prepare_anglo_saxon_out_lines_hook/hooks.py
Normal file
@@ -0,0 +1,67 @@
|
||||
# Copyright 2020 ForgeFlow, S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo.addons.stock_account.models.account_move import AccountMove
|
||||
|
||||
|
||||
def post_load_hook():
|
||||
def new_stock_account_prepare_anglo_saxon_out_lines_vals(self):
|
||||
lines_vals_list = []
|
||||
for move in self:
|
||||
if (
|
||||
not move.is_sale_document(include_receipts=True)
|
||||
or not move.company_id.anglo_saxon_accounting
|
||||
):
|
||||
continue
|
||||
|
||||
for line in move.invoice_line_ids:
|
||||
|
||||
# Filter out lines being not eligible for COGS.
|
||||
# FIRST HOOK STARTS
|
||||
if not line._eligible_for_cogs():
|
||||
continue
|
||||
# FIRST HOOK ENDS
|
||||
|
||||
# Retrieve accounts needed to generate the COGS.
|
||||
accounts = line.product_id.product_tmpl_id.with_context(
|
||||
force_company=line.company_id.id
|
||||
).get_product_accounts(fiscal_pos=move.fiscal_position_id)
|
||||
debit_interim_account = accounts["stock_output"]
|
||||
credit_expense_account = accounts["expense"]
|
||||
if not credit_expense_account:
|
||||
if self.type == "out_refund":
|
||||
credit_expense_account = (
|
||||
self.journal_id.default_credit_account_id
|
||||
)
|
||||
else: # out_invoice/out_receipt
|
||||
credit_expense_account = (
|
||||
self.journal_id.default_debit_account_id
|
||||
)
|
||||
if not debit_interim_account or not credit_expense_account:
|
||||
continue
|
||||
|
||||
# Add interim account line.
|
||||
# SECOND HOOK STARTS
|
||||
if not debit_interim_account or not credit_expense_account:
|
||||
continue
|
||||
interim_account_line_vals = self._prepare_interim_account_line_vals(
|
||||
line, move, debit_interim_account
|
||||
)
|
||||
lines_vals_list.append(interim_account_line_vals)
|
||||
expense_account_line_vals = self._prepare_expense_account_line_vals(
|
||||
line, move, credit_expense_account
|
||||
)
|
||||
lines_vals_list.append(expense_account_line_vals)
|
||||
# SECOND HOOK ENDS
|
||||
return lines_vals_list
|
||||
|
||||
if not hasattr(
|
||||
AccountMove, "stock_account_prepare_anglo_saxon_out_lines_vals_original"
|
||||
):
|
||||
AccountMove.stock_account_prepare_anglo_saxon_out_lines_vals_original = (
|
||||
AccountMove._stock_account_prepare_anglo_saxon_out_lines_vals
|
||||
)
|
||||
|
||||
AccountMove._stock_account_prepare_anglo_saxon_out_lines_vals = (
|
||||
new_stock_account_prepare_anglo_saxon_out_lines_vals
|
||||
)
|
||||
@@ -0,0 +1,4 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import account_move
|
||||
from . import account_move_line
|
||||
@@ -0,0 +1,49 @@
|
||||
# Copyright 2020 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
|
||||
_inherit = "account.move"
|
||||
|
||||
def _prepare_interim_account_line_vals(self, line, move, debit_interim_account):
|
||||
# Compute accounting fields.
|
||||
sign = -1 if move.type == "out_refund" else 1
|
||||
price_unit = line._stock_account_get_anglo_saxon_price_unit()
|
||||
balance = sign * line.quantity * price_unit
|
||||
return {
|
||||
"name": line.name[:64],
|
||||
"move_id": move.id,
|
||||
"product_id": line.product_id.id,
|
||||
"product_uom_id": line.product_uom_id.id,
|
||||
"quantity": line.quantity,
|
||||
"price_unit": price_unit,
|
||||
"debit": balance < 0.0 and -balance or 0.0,
|
||||
"credit": balance > 0.0 and balance or 0.0,
|
||||
"account_id": debit_interim_account.id,
|
||||
"exclude_from_invoice_tab": True,
|
||||
"is_anglo_saxon_line": True,
|
||||
}
|
||||
|
||||
def _prepare_expense_account_line_vals(self, line, move, credit_expense_account):
|
||||
# Compute accounting fields.
|
||||
sign = -1 if move.type == "out_refund" else 1
|
||||
price_unit = line._stock_account_get_anglo_saxon_price_unit()
|
||||
balance = sign * line.quantity * price_unit
|
||||
return {
|
||||
"name": line.name[:64],
|
||||
"move_id": move.id,
|
||||
"product_id": line.product_id.id,
|
||||
"product_uom_id": line.product_uom_id.id,
|
||||
"quantity": line.quantity,
|
||||
"price_unit": -price_unit,
|
||||
"debit": balance > 0.0 and balance or 0.0,
|
||||
"credit": balance < 0.0 and -balance or 0.0,
|
||||
"account_id": credit_expense_account.id,
|
||||
"analytic_account_id": line.analytic_account_id.id,
|
||||
"analytic_tag_ids": [(6, 0, line.analytic_tag_ids.ids)],
|
||||
"exclude_from_invoice_tab": True,
|
||||
"is_anglo_saxon_line": True,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
# Copyright 2020 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
def _eligible_for_cogs(self):
|
||||
self.ensure_one()
|
||||
return (
|
||||
self.product_id.type == "product"
|
||||
and self.product_id.valuation == "real_time"
|
||||
)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
Reference in New Issue
Block a user