2
0

[15.0][MIG] account_move_line_sale_info: Migration to 15.0

This commit is contained in:
Joan Mateu Jordi 2021-11-09 14:38:50 +01:00 committed by AlexPForgeFlow
parent 625a2090f9
commit 6ecee22a46
11 changed files with 40 additions and 61 deletions

View File

@ -44,6 +44,7 @@ Images
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------

View File

@ -4,14 +4,13 @@
{
"name": "Account Move Line Sale Info",
"summary": "Introduces the purchase order line to the journal items",
"version": "13.0.1.0.3",
"version": "15.0.1.0.0",
"author": "ForgeFlow S.L., " "Odoo Community Association (OCA)",
"website": "http://www.github.com/OCA/account-financial-tools",
"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"],

View File

@ -4,7 +4,7 @@
def post_init_hook(cr, registry):
""" INIT sale references in acount move line """
"""INIT sale references in account move line"""
# FOR stock moves
cr.execute(
"""

View File

@ -1,12 +0,0 @@
# Copyright 2020 ForgeFlow <http://www.forgeflow.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openupgradelib import openupgrade
_field_renames = [
("account.move.line", "account_move_line", "sale_id", "sale_order_id",),
]
@openupgrade.migrate()
def migrate(env, version):
openupgrade.rename_fields(env, _field_renames)

View File

@ -5,45 +5,24 @@ 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
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):
if (
not vals.get("move_id", False)
or not vals.get("product_id", False)
or not vals.get("quantity", False)
):
continue
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_id")
if sale_line_id and len(sale_line_id) == 1:
res[i]["sale_line_id"] = sale_line_id.id
return res

View File

@ -19,7 +19,7 @@ class SaleOrderLine(models.Model):
result.append((line.id, name))
return result
def _prepare_invoice_line(self):
res = super(SaleOrderLine, self)._prepare_invoice_line()
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 @@
* 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

@ -66,9 +66,9 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
)
def _create_user(self, login, groups, company):
""" Create a user."""
"""Create a user."""
group_ids = [group.id for group in groups]
user = self.res_users_model.with_context({"no_reset_password": True}).create(
user = self.res_users_model.with_context(**{"no_reset_password": True}).create(
{
"name": "Test User",
"login": login,
@ -123,7 +123,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
return product
def _create_sale(self, line_products):
""" Create a sale order.
"""Create a sale order.
``line_products`` is a list of tuple [(product, qty)]
"""
@ -198,7 +198,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
}
payment = (
self.env["sale.advance.payment.inv"]
.with_context(self.context)
.with_context(**self.context)
.create({"advance_payment_method": "delivered"})
)
payment.create_invoices()
@ -217,7 +217,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
def test_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}).name_get()
self.assertEqual(
name_get,
[
@ -232,7 +232,7 @@ class TestAccountMoveLineSaleInfo(common.TransactionCase):
)
],
)
name_get_no_ctx = so_line.with_context({}).name_get()
name_get_no_ctx = so_line.with_context(**{}).name_get()
self.assertEqual(
name_get_no_ctx,
[