Skip to content

Commit

Permalink
Merge PR OCA#1261 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by kittiu
  • Loading branch information
OCA-git-bot committed Nov 12, 2021
2 parents 1e8781c + fc960ea commit 26f9443
Show file tree
Hide file tree
Showing 14 changed files with 682 additions and 0 deletions.
65 changes: 65 additions & 0 deletions account_move_line_sale_info/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.. image:: https://img.shields.io/badge/license-AGPLv3-blue.svg
:target: https://www.gnu.org/licenses/agpl.html
:alt: License: AGPL-3

===========================
Account Move Line Sale Info
===========================

This module will add the sale order line to journal items.

The ultimate goal is to establish the purchase order line as one of the key
fields to reconcile the Goods Delivered Not Invoiced accrual account.


Usage
=====

The sale order line will be automatically copied to the journal items.

* When a supplier invoice is created referencing sales orders, the
sale order line will be copied to the corresponding journal item.

* When a stock move is validated and generates a journal entry, the sale
order line is copied to the account move line.

.. 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 <[email protected]>

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.
4 changes: 4 additions & 0 deletions account_move_line_sale_info/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import models
from .hooks import post_init_hook
20 changes: 20 additions & 0 deletions account_move_line_sale_info/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Account Move Line Sale Info",
"summary": "Introduces the purchase order line to the journal items",
"version": "14.0.1.0.0",
"author": "ForgeFlow S.L., " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"category": "Generic",
"depends": [
"account_move_line_stock_info",
"sale_stock",
"stock_account_prepare_anglo_saxon_out_lines_hook",
],
"license": "AGPL-3",
"data": ["security/account_security.xml", "views/account_move_view.xml"],
"installable": True,
"post_init_hook": "post_init_hook",
}
70 changes: 70 additions & 0 deletions account_move_line_sale_info/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2019 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


def post_init_hook(cr, registry):

""" INIT sale references in acount move line """
# FOR stock moves
cr.execute(
"""
UPDATE account_move_line aml SET sale_line_id = sm.sale_line_id
FROM account_move_line aml2
INNER JOIN stock_move sm ON
aml2.stock_move_id = sm.id
WHERE aml.id = aml2.id;
"""
)
# FOR invoices
cr.execute(
"""
UPDATE account_move_line aml SET sale_line_id = sol.id
FROM account_move_line aml2
INNER JOIN account_move am ON
am.id = aml2.move_id
INNER JOIN sale_order_line_invoice_rel rel ON
rel.invoice_line_id = aml2.id
INNER JOIN sale_order_line sol ON
rel.order_line_id = sol.id
AND sol.product_id = aml2.product_id
WHERE aml.id = aml2.id;
"""
)

# NOW we can fill the SO
cr.execute(
"""
UPDATE account_move_line aml
SET sale_order_id = sol.order_id
FROM sale_order_line AS sol
WHERE aml.sale_line_id = sol.id
RETURNING aml.move_id
"""
)

# NOW we can fill the lines without invoice_id (Odoo put it very
# complicated)

cr.execute(
"""
UPDATE account_move_line aml
SET sale_order_id = so.id
FROM sale_order so
LEFT JOIN account_move_line aml2
ON aml2.sale_order_id = so.id
WHERE aml2.move_id = aml.move_id
"""
)

cr.execute(
"""
update account_move_line aml set sale_line_id = sol.id
FROM account_move_line aml2
INNER JOIN sale_order so ON
so.id = aml2.sale_order_id
INNER JOIN sale_order_line sol ON
so.id = sol.order_id
AND sol.product_id = aml2.product_id
WHERE aml.id = aml2.id;
"""
)
55 changes: 55 additions & 0 deletions account_move_line_sale_info/i18n/account_move_line_sale_info.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_move_line_sale_info
#
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: account_move_line_sale_info
#: model:ir.model,name:account_move_line_sale_info.model_account_move
msgid "Journal Entries"
msgstr ""

#. module: account_move_line_sale_info
#: model:ir.model,name:account_move_line_sale_info.model_account_move_line
msgid "Journal Item"
msgstr ""

#. module: account_move_line_sale_info
#: model_terms:ir.ui.view,arch_db:account_move_line_sale_info.view_account_move_line_filter
msgid "Sale Order"
msgstr ""

#. module: account_move_line_sale_info
#: model:ir.model.fields,field_description:account_move_line_sale_info.field_account_move_line__sale_line_id
#: model_terms:ir.ui.view,arch_db:account_move_line_sale_info.view_account_move_line_filter
msgid "Sale Order Line"
msgstr ""

#. module: account_move_line_sale_info
#: model:res.groups,name:account_move_line_sale_info.group_account_move_sale_info
msgid "Sale info in Journal Items"
msgstr ""

#. module: account_move_line_sale_info
#: model:ir.model.fields,field_description:account_move_line_sale_info.field_account_move_line__sale_order_id
msgid "Sales Order"
msgstr ""

#. module: account_move_line_sale_info
#: model:ir.model,name:account_move_line_sale_info.model_sale_order_line
msgid "Sales Order Line"
msgstr ""

#. module: account_move_line_sale_info
#: model:ir.model,name:account_move_line_sale_info.model_stock_move
msgid "Stock Move"
msgstr ""
5 changes: 5 additions & 0 deletions account_move_line_sale_info/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import account_move
from . import sale_order_line
from . import stock_move
70 changes: 70 additions & 0 deletions account_move_line_sale_info/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class AccountMove(models.Model):

_inherit = "account.move"

def _prepare_interim_account_line_vals(self, line, move, debit_interim_account):
res = super()._prepare_interim_account_line_vals(
line, move, debit_interim_account
)
if (
not res.get("move_id", False)
or not res.get("product_id", False)
or not res.get("quantity", False)
):
return res
am = self.env["account.move"].browse(res["move_id"])
sale_line_id = am.invoice_line_ids.filtered(
lambda il: il.product_id.id == res["product_id"]
and il.quantity == res["quantity"]
).mapped("sale_line_id")
if sale_line_id and len(sale_line_id) == 1:
res["sale_line_id"] = sale_line_id.id
return res

def _prepare_expense_account_line_vals(self, line, move, debit_interim_account):
res = super()._prepare_expense_account_line_vals(
line, move, debit_interim_account
)
if (
not res.get("move_id", False)
or not res.get("product_id", False)
or not res.get("quantity", False)
):
return res
am = self.env["account.move"].browse(res["move_id"])
sale_line_id = am.invoice_line_ids.filtered(
lambda il: il.product_id.id == res["product_id"]
and il.quantity == res["quantity"]
).mapped("sale_line_id")
if sale_line_id and len(sale_line_id) == 1:
res["sale_line_id"] = sale_line_id.id
return res


class AccountMoveLine(models.Model):

_inherit = "account.move.line"

sale_line_id = fields.Many2one(
comodel_name="sale.order.line",
string="Sale Order Line",
ondelete="set null",
index=True,
copy=False,
)

sale_order_id = fields.Many2one(
comodel_name="sale.order",
related="sale_line_id.order_id",
string="Sales Order",
ondelete="set null",
store=True,
index=True,
copy=False,
)
25 changes: 25 additions & 0 deletions account_move_line_sale_info/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

def name_get(self):
result = []
orig_name = dict(super(SaleOrderLine, self).name_get())
for line in self:
name = orig_name[line.id]
if self.env.context.get("so_line_info", False):
name = "[{}] {} - ({})".format(
line.order_id.name, line.product_id.name, line.order_id.state
)
result.append((line.id, name))
return result

def _prepare_invoice_line(self, **optional_values):
res = super(SaleOrderLine, self)._prepare_invoice_line(**optional_values)
res["sale_line_id"] = self.id
return res
18 changes: 18 additions & 0 deletions account_move_line_sale_info/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2020 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models


class StockMove(models.Model):
_inherit = "stock.move"

@api.model
def _prepare_account_move_line(
self, qty, cost, credit_account_id, debit_account_id, description
):
res = super(StockMove, self)._prepare_account_move_line(
qty, cost, credit_account_id, debit_account_id, description
)
for line in res:
line[2]["sale_line_id"] = self.sale_line_id.id
return res
8 changes: 8 additions & 0 deletions account_move_line_sale_info/security/account_security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="group_account_move_sale_info" model="res.groups">
<field name="name">Sale info in Journal Items</field>
<field name="category_id" ref="base.module_category_hidden" />
<field name="users" eval="[(4, ref('base.user_admin'))]" />
</record>
</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions account_move_line_sale_info/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from . import test_account_move_line_sale_info
Loading

0 comments on commit 26f9443

Please sign in to comment.