Merge PR #1260 into 14.0

Signed-off-by AaronHForgeFlow
This commit is contained in:
OCA-git-bot
2021-11-05 19:41:28 +00:00
11 changed files with 238 additions and 0 deletions

View File

@@ -0,0 +1 @@
../../../../stock_account_prepare_anglo_saxon_out_lines_hook

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View 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.

View File

@@ -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

View File

@@ -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": "14.0.1.0.0",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"category": "Generic",
"depends": ["stock_account"],
"post_load": "post_load_hook",
"license": "AGPL-3",
"installable": True,
}

View File

@@ -0,0 +1,57 @@
# 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_company(
line.company_id
).get_product_accounts(fiscal_pos=move.fiscal_position_id)
debit_interim_account = accounts["stock_output"]
credit_expense_account = (
accounts["expense"] or self.journal_id.default_account_id
)
if not debit_interim_account or not credit_expense_account:
continue
# Add interim account line.
# SECOND HOOK STARTS
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
)

View File

@@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_account_prepare_anglo_saxon_out_lines_hook
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: stock_account_prepare_anglo_saxon_out_lines_hook
#: model:ir.model,name:stock_account_prepare_anglo_saxon_out_lines_hook.model_account_move
msgid "Journal Entries"
msgstr ""
#. module: stock_account_prepare_anglo_saxon_out_lines_hook
#: model:ir.model,name:stock_account_prepare_anglo_saxon_out_lines_hook.model_account_move_line
msgid "Journal Item"
msgstr ""

View File

@@ -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

View File

@@ -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,
}

View File

@@ -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