[MIG] account_move_line_sale_info: migration to V17

This commit is contained in:
andrea
2024-08-30 15:56:41 +02:00
parent 2ef2e8c46e
commit 9cd0d1aad8
11 changed files with 54 additions and 58 deletions

View File

@@ -30,9 +30,8 @@ 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.
The ultimate goal is to establish the sale order line as one of the key
fields to reconcile the Goods Delivered Not Invoiced accrual account.
**Table of contents**
@@ -44,7 +43,7 @@ Usage
The sale order line will be automatically copied to the journal items.
- When a supplier invoice is created referencing sales orders, the sale
- When a customer 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.
@@ -71,6 +70,9 @@ Contributors
------------
- Aaron Henriquez <ahenriquez@forgeflow.com>
- `360ERP <https://www.360erp.com>`__:
- Andrea Stirpe
Maintainers
-----------

View File

@@ -4,7 +4,7 @@
{
"name": "Account Move Line Sale Info",
"summary": "Introduces the purchase order line to the journal items",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"author": "ForgeFlow S.L., " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-financial-tools",
"category": "Generic",

View File

@@ -2,11 +2,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
def post_init_hook(cr, registry):
def post_init_hook(env):
"""INIT sale references in account move line"""
# FOR stock moves
cr.execute(
env.cr.execute(
"""
UPDATE account_move_line aml SET sale_line_id = sm.sale_line_id
FROM account_move_line aml2
@@ -16,7 +15,7 @@ def post_init_hook(cr, registry):
"""
)
# FOR invoices
cr.execute(
env.cr.execute(
"""
UPDATE account_move_line aml SET sale_line_id = sol.id
FROM account_move_line aml2
@@ -32,7 +31,7 @@ def post_init_hook(cr, registry):
)
# NOW we can fill the SO
cr.execute(
env.cr.execute(
"""
UPDATE account_move_line aml
SET sale_order_id = sol.order_id
@@ -45,7 +44,7 @@ def post_init_hook(cr, registry):
# NOW we can fill the lines without invoice_id (Odoo put it very
# complicated)
cr.execute(
env.cr.execute(
"""
UPDATE account_move_line aml
SET sale_order_id = so.id
@@ -56,7 +55,7 @@ def post_init_hook(cr, registry):
"""
)
cr.execute(
env.cr.execute(
"""
update account_move_line aml set sale_line_id = sol.id
FROM account_move_line aml2

View File

@@ -12,8 +12,8 @@ class AccountMove(models.Model):
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"]
lambda il, vs=vals: il.product_id.id == vs["product_id"]
and il.quantity == vs["quantity"]
).mapped("sale_line_ids")
if sale_line_id and len(sale_line_id) == 1:
res[i]["sale_line_id"] = sale_line_id.id
@@ -21,7 +21,6 @@ class AccountMove(models.Model):
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
sale_line_id = fields.Many2one(
@@ -44,6 +43,6 @@ class AccountMoveLine(models.Model):
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)
res = super()._copy_data_extend_business_fields(values)
values["sale_line_id"] = self.sale_line_id.id
return res

View File

@@ -1,23 +1,23 @@
# Copyright 2020-23 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import models
from odoo import api, 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):
@api.depends()
@api.depends_context("so_line_info")
def _compute_display_name(self):
res = super()._compute_display_name()
if self.env.context.get("so_line_info", False):
for line in self.sudo():
name = "[{}] {} - ({})".format(
line.order_id.name, line.product_id.name, line.order_id.state
)
result.append((line.id, name))
return result
line.display_name = name
return res
def _prepare_invoice_line(self, **optional_values):
res = super()._prepare_invoice_line(**optional_values)

View File

@@ -10,7 +10,7 @@ class StockMove(models.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(
res = super()._prepare_account_move_line(
qty, cost, credit_account_id, debit_account_id, svl_id, description
)
for line in res:

View File

@@ -1 +1,3 @@
- Aaron Henriquez \<<ahenriquez@forgeflow.com>\>
- [360ERP](https://www.360erp.com):
- Andrea Stirpe

View File

@@ -1,5 +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.
The ultimate goal is to establish the sale order line as one of the key
fields to reconcile the Goods Delivered Not Invoiced accrual account.

View File

@@ -1,6 +1,6 @@
The sale order line will be automatically copied to the journal items.
- When a supplier invoice is created referencing sales orders, the sale
- When a customer 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

@@ -371,9 +371,8 @@ ul.auto-toc {
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/account-financial-tools/tree/17.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 image-reference" href="https://translation.odoo-community.org/projects/account-financial-tools-17-0/account-financial-tools-17-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 image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-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>The ultimate goal is to establish the sale 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">
@@ -391,7 +390,7 @@ account.</p>
<h1><a class="toc-backref" href="#toc-entry-1">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
<li>When a customer 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>
@@ -417,6 +416,10 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<h2><a class="toc-backref" href="#toc-entry-5">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>
<li><a class="reference external" href="https://www.360erp.com">360ERP</a>:<ul>
<li>Andrea Stirpe</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">

View File

@@ -5,7 +5,7 @@ from odoo.tests import common
class TestAccountMoveLineSaleInfo(common.TransactionCase):
def setUp(self):
super(TestAccountMoveLineSaleInfo, self).setUp()
super().setUp()
self.sale_model = self.env["sale.order"]
self.sale_line_model = self.env["sale.order.line"]
self.product_model = self.env["product.product"]
@@ -159,8 +159,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
self.assertEqual(
balance,
expected_balance,
"Balance is not %s for sale Line %s."
% (str(expected_balance), sale_line.name),
f"Balance is not {str(expected_balance)} for sale Line {sale_line.name}.",
)
def move_reversal_wiz(self, move):
@@ -182,7 +181,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
break
sale.action_confirm()
picking = sale.picking_ids[0]
picking.move_ids.write({"quantity_done": 1.0})
picking.move_ids.write({"quantity": 1.0, "picked": True})
picking.button_validate()
expected_balance = -1.0
@@ -218,30 +217,23 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
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()
name_get = so_line.with_context(**{"so_line_info": True}).display_name
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,
),
)
],
"[{}] {} - ({})".format(
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()
name_get_no_ctx = so_line.with_context(**{}).display_name
self.assertEqual(
name_get_no_ctx,
[
(
so_line.id,
"{} - {}".format(so_line.order_id.name, so_line.product_id.name),
)
],
"{} - {} {}".format(
so_line.order_id.name,
so_line.product_id.name,
so_line._additional_name_per_id()[so_line.id],
),
)
def test_03_credit_note(self):
@@ -253,7 +245,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
break
sale.action_confirm()
picking = sale.picking_ids[0]
picking.move_ids.write({"quantity_done": 1.0})
picking.move_ids.write({"quantity": 1.0, "picked": True})
picking.button_validate()
sale._create_invoices()
invoice = sale.invoice_ids[0]