2
0

Merge PR #1711 into 16.0

Signed-off-by AaronHForgeFlow
This commit is contained in:
OCA-git-bot 2023-08-08 10:51:51 +00:00
commit d54eddc9e2
21 changed files with 1219 additions and 0 deletions

View File

@ -0,0 +1,87 @@
===========================
Account Move Line Sale Info
===========================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github
:target: https://github.com/OCA/account-financial-tools/tree/15.0/account_move_line_sale_info
:alt: OCA/account-financial-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-account_move_line_sale_info
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/92/15.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
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.
**Table of contents**
.. contents::
:local:
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.
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 <https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_line_sale_info%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* ForgeFlow S.L.
Contributors
~~~~~~~~~~~~
* Aaron Henriquez <ahenriquez@forgeflow.com>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
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.
This module is part of the `OCA/account-financial-tools <https://github.com/OCA/account-financial-tools/tree/15.0/account_move_line_sale_info>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

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_init_hook

View File

@ -0,0 +1,19 @@
# Copyright 2020-23 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": "16.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",
],
"license": "AGPL-3",
"data": ["security/account_security.xml", "views/account_move_view.xml"],
"installable": True,
"post_init_hook": "post_init_hook",
}

View File

@ -0,0 +1,70 @@
# Copyright 2019-23 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 account 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;
"""
)

View File

@ -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 15.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 Entry"
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 ""

View File

@ -0,0 +1,58 @@
# 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 15.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2022-05-23 06:05+0000\n"
"Last-Translator: Ignacio Buioli <ibuioli@gmail.com>\n"
"Language-Team: none\n"
"Language: es_AR\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.3.2\n"
#. module: account_move_line_sale_info
#: model:ir.model,name:account_move_line_sale_info.model_account_move
msgid "Journal Entry"
msgstr "Asiento Contable"
#. module: account_move_line_sale_info
#: model:ir.model,name:account_move_line_sale_info.model_account_move_line
msgid "Journal Item"
msgstr "Apunte Contable"
#. 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 "Pedido de Venta"
#. 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 "Línea de Pedido de Venta"
#. 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 "Información de Venta de los Apuntes Contables"
#. 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 "Pedido de Venta"
#. module: account_move_line_sale_info
#: model:ir.model,name:account_move_line_sale_info.model_sale_order_line
msgid "Sales Order Line"
msgstr "Línea de Pedido de Venta"
#. module: account_move_line_sale_info
#: model:ir.model,name:account_move_line_sale_info.model_stock_move
msgid "Stock Move"
msgstr "Movimiento de Inventario"

View File

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

View File

@ -0,0 +1,49 @@
# Copyright 2020-23 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 _stock_account_prepare_anglo_saxon_out_lines_vals(self):
res = super()._stock_account_prepare_anglo_saxon_out_lines_vals()
for i, vals in enumerate(res):
am = self.env["account.move"].browse(vals["move_id"])
sale_line_id = am.invoice_line_ids.filtered(
lambda il: il.product_id.id == vals["product_id"]
and il.quantity == vals["quantity"]
).mapped("sale_line_ids")
if sale_line_id and len(sale_line_id) == 1:
res[i]["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,
)
def _copy_data_extend_business_fields(self, values):
# Same way Odoo standard does for purchase_line_id field
res = super(AccountMoveLine, self)._copy_data_extend_business_fields(values)
values["sale_line_id"] = self.sale_line_id.id
return res

View File

@ -0,0 +1,25 @@
# Copyright 2020-23 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()._prepare_invoice_line(**optional_values)
res["sale_line_id"] = self.id
return res

View File

@ -0,0 +1,18 @@
# Copyright 2020-23 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, svl_id, description
):
res = super(StockMove, self)._prepare_account_move_line(
qty, cost, credit_account_id, debit_account_id, svl_id, description
)
for line in res:
line[2]["sale_line_id"] = self.sale_line_id.id
return res

View File

@ -0,0 +1 @@
* Aaron Henriquez <ahenriquez@forgeflow.com>

View File

@ -0,0 +1,4 @@
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.

View File

@ -0,0 +1,7 @@
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.

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -0,0 +1,432 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Account Move Line Sale Info</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="account-move-line-sale-info">
<h1 class="title">Account Move Line Sale Info</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/15.0/account_move_line_sale_info"><img alt="OCA/account-financial-tools" src="https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/account-financial-tools-15-0/account-financial-tools-15-0-account_move_line_sale_info"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/92/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module will add the sale order line to journal items.</p>
<p>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.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>The sale order line will be automatically copied to the journal items.</p>
<ul class="simple">
<li>When a supplier invoice is created referencing sales orders, the
sale order line will be copied to the corresponding journal item.</li>
<li>When a stock move is validated and generates a journal entry, the sale
order line is copied to the account move line.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/account-financial-tools/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/account-financial-tools/issues/new?body=module:%20account_move_line_sale_info%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple">
<li>ForgeFlow S.L.</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li>Aaron Henriquez &lt;<a class="reference external" href="mailto:ahenriquez&#64;forgeflow.com">ahenriquez&#64;forgeflow.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/account-financial-tools/tree/15.0/account_move_line_sale_info">OCA/account-financial-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

View File

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

View File

@ -0,0 +1,272 @@
# Copyright 2020-23 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.tests import common
class TestAccountMoveLineSaleInfo(common.TransactionCase):
def setUp(self):
super(TestAccountMoveLineSaleInfo, self).setUp()
self.sale_model = self.env["sale.order"]
self.sale_line_model = self.env["sale.order.line"]
self.product_model = self.env["product.product"]
self.product_ctg_model = self.env["product.category"]
self.account_model = self.env["account.account"]
self.aml_model = self.env["account.move.line"]
self.res_users_model = self.env["res.users"]
self.partner1 = self.env.ref("base.res_partner_1")
self.location_stock = self.env.ref("stock.stock_location_stock")
self.company = self.env.ref("base.main_company")
self.group_sale_user = self.env.ref("sales_team.group_sale_salesman")
self.group_account_invoice = self.env.ref("account.group_account_invoice")
self.group_account_manager = self.env.ref("account.group_account_manager")
# Create account for Goods Received Not Invoiced
acc_type = "equity"
name = "Goods Received Not Invoiced"
code = "grni"
self.account_grni = self._create_account(acc_type, name, code, self.company)
# Create account for Cost of Goods Sold
acc_type = "expense"
name = "Cost of Goods Sold"
code = "cogs"
self.account_cogs = self._create_account(acc_type, name, code, self.company)
# Create account for Inventory
acc_type = "asset_fixed"
name = "Inventory"
code = "inventory"
self.account_inventory = self._create_account(
acc_type, name, code, self.company
)
# Create Product
self.product = self._create_product()
# Create users
self.sale_user = self._create_user(
"sale_user",
[self.group_sale_user, self.group_account_invoice],
self.company,
)
self.account_invoice = self._create_user(
"account_invoice", [self.group_account_invoice], self.company
)
self.account_manager = self._create_user(
"account_manager", [self.group_account_manager], self.company
)
self.JournalObj = self.env["account.journal"]
self.journal_sale = self.JournalObj.create(
{
"name": "Test journal sale",
"code": "TST-JRNL-S",
"type": "sale",
"company_id": self.company.id,
}
)
def _create_user(self, login, groups, company):
"""Create a user."""
group_ids = [group.id for group in groups]
user = self.res_users_model.with_context(**{"no_reset_password": True}).create(
{
"name": "Test User",
"login": login,
"password": "demo",
"email": "test@yourcompany.com",
"company_id": company.id,
"company_ids": [(4, company.id)],
"groups_id": [(6, 0, group_ids)],
}
)
return user.id
def _create_account(self, acc_type, name, code, company):
"""Create an account."""
account = self.account_model.create(
{
"name": name,
"code": code,
"account_type": acc_type,
"company_id": company.id,
}
)
return account
def _create_product(self):
"""Create a Product."""
# group_ids = [group.id for group in groups]
product_ctg = self.product_ctg_model.create(
{
"name": "test_product_ctg",
"property_stock_valuation_account_id": self.account_inventory.id,
"property_valuation": "real_time",
"property_stock_account_input_categ_id": self.account_grni.id,
"property_stock_account_output_categ_id": self.account_cogs.id,
}
)
product = self.product_model.create(
{
"name": "test_product",
"categ_id": product_ctg.id,
"type": "product",
"standard_price": 1.0,
"list_price": 1.0,
}
)
return product
def _create_sale(self, line_products):
"""Create a sale order.
``line_products`` is a list of tuple [(product, qty)]
"""
lines = []
for product, qty in line_products:
line_values = {
"name": product.name,
"product_id": product.id,
"product_uom_qty": qty,
"product_uom": product.uom_id.id,
"price_unit": 500,
}
lines.append((0, 0, line_values))
return self.sale_model.create(
{"partner_id": self.partner1.id, "order_line": lines}
)
def _get_balance(self, domain):
"""
Call read_group method and return the balance of particular account.
"""
aml_rec = self.aml_model.read_group(
domain, ["debit", "credit", "account_id"], ["account_id"]
)
if aml_rec:
return aml_rec[0].get("debit", 0) - aml_rec[0].get("credit", 0)
else:
return 0.0
def _check_account_balance(self, account_id, sale_line=None, expected_balance=0.0):
"""
Check the balance of the account
"""
domain = [("account_id", "=", account_id)]
if sale_line:
domain.extend([("sale_line_id", "=", sale_line.id)])
balance = self._get_balance(domain)
if sale_line:
self.assertEqual(
balance,
expected_balance,
"Balance is not %s for sale Line %s."
% (str(expected_balance), sale_line.name),
)
def move_reversal_wiz(self, move):
wizard = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=[move.id])
.create({"journal_id": move.journal_id.id})
)
return wizard
def test_01_sale_invoice(self):
"""Test that the po line moves from the sale order to the
account move line and to the invoice line.
"""
sale = self._create_sale([(self.product, 1)])
so_line = False
for line in sale.order_line:
so_line = line
break
sale.action_confirm()
picking = sale.picking_ids[0]
picking.move_ids.write({"quantity_done": 1.0})
picking.button_validate()
expected_balance = -1.0
self._check_account_balance(
self.account_inventory.id,
sale_line=so_line,
expected_balance=expected_balance,
)
self.context = {
"active_model": "sale.order",
"active_ids": [sale.id],
"active_id": sale.id,
"default_journal_id": self.journal_sale.id,
}
payment = (
self.env["sale.advance.payment.inv"]
.with_context(**self.context)
.create({"advance_payment_method": "delivered"})
)
payment.create_invoices()
invoice = sale.invoice_ids[0]
invoice._post()
for aml in invoice.line_ids:
if aml.product_id == so_line.product_id and aml.move_id:
self.assertEqual(
aml.sale_line_id,
so_line,
"sale Order line has not been copied "
"from the invoice to the account move line.",
)
def test_02_name_get(self):
sale = self._create_sale([(self.product, 1)])
so_line = sale.order_line[0]
name_get = so_line.with_context(**{"so_line_info": True}).name_get()
self.assertEqual(
name_get,
[
(
so_line.id,
"[%s] %s - (%s)"
% (
so_line.order_id.name,
so_line.product_id.name,
so_line.order_id.state,
),
)
],
)
name_get_no_ctx = so_line.with_context(**{}).name_get()
self.assertEqual(
name_get_no_ctx,
[
(
so_line.id,
"{} - {}".format(so_line.order_id.name, so_line.product_id.name),
)
],
)
def test_03_credit_note(self):
"""Test the credit note is linked to the sale order line"""
sale = self._create_sale([(self.product, 1)])
so_line = False
for line in sale.order_line:
so_line = line
break
sale.action_confirm()
picking = sale.picking_ids[0]
picking.move_ids.write({"quantity_done": 1.0})
picking.button_validate()
sale._create_invoices()
invoice = sale.invoice_ids[0]
invoice._post()
reversal_wizard = self.move_reversal_wiz(invoice)
credit_note = self.env["account.move"].browse(
reversal_wizard.reverse_moves()["res_id"]
)
for aml in credit_note.line_ids:
if aml.product_id == so_line.product_id and aml.move_id:
self.assertEqual(
aml.sale_line_id,
so_line,
"sale Order line has not been copied "
"from the invoice to the credit note.",
)

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_move_line_form" model="ir.ui.view">
<field name="name">account.move.line.form</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_form" />
<field name="arch" type="xml">
<field name="quantity" position="before">
<field
name="sale_order_id"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
<field
name="sale_line_id"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
</field>
</field>
</record>
<record id="view_move_line_tree" model="ir.ui.view">
<field name="name">account.move.line.tree</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_move_line_tree" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field
name="sale_order_id"
optional="show"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
<field
name="sale_line_id"
optional="hide"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
</field>
</field>
</record>
<record id="view_account_move_line_filter" model="ir.ui.view">
<field name="name">Journal Items</field>
<field name="model">account.move.line</field>
<field name="inherit_id" ref="account.view_account_move_line_filter" />
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field
name="sale_order_id"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
<field
name="sale_line_id"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
</field>
<filter name="group_by_partner" position="after">
<filter
name="group_by_sale_order"
string="Sale Order"
domain="[]"
context="{'group_by':'sale_order_id'}"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
<filter
name="group_by_sale_order_line"
string="Sale Order Line"
domain="[]"
context="{'group_by':'sale_line_id','so_line_info':True}"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
</filter>
</field>
</record>
<record id="view_move_form" model="ir.ui.view">
<field name="name">account.move.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='line_ids']/tree//field[@name='partner_id']"
position="after"
>
<field
name="sale_line_id"
context="{'so_line_info': True}"
optional="hide"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
<field
name="sale_order_id"
optional="show"
groups="account_move_line_sale_info.group_account_move_sale_info"
/>
</xpath>
</field>
</record>
</odoo>

View File

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

View File

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