2023-08-04 11:10:11 +02:00
|
|
|
# Copyright 2020-23 ForgeFlow S.L.
|
2020-05-15 15:12:20 +02:00
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
from odoo import fields, models
|
|
|
|
|
|
|
|
|
2021-05-03 14:04:28 +02:00
|
|
|
class AccountMove(models.Model):
|
|
|
|
_inherit = "account.move"
|
|
|
|
|
2021-11-09 14:38:50 +01:00
|
|
|
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"]
|
2022-12-19 17:40:22 +01:00
|
|
|
).mapped("sale_line_ids")
|
2021-11-09 14:38:50 +01:00
|
|
|
if sale_line_id and len(sale_line_id) == 1:
|
|
|
|
res[i]["sale_line_id"] = sale_line_id.id
|
2021-05-03 14:04:28 +02:00
|
|
|
return res
|
|
|
|
|
|
|
|
|
2020-05-15 15:12:20 +02:00
|
|
|
class AccountMoveLine(models.Model):
|
|
|
|
|
2020-07-29 17:26:15 +02:00
|
|
|
_inherit = "account.move.line"
|
2020-05-15 15:12:20 +02:00
|
|
|
|
|
|
|
sale_line_id = fields.Many2one(
|
2020-07-29 17:26:15 +02:00
|
|
|
comodel_name="sale.order.line",
|
|
|
|
string="Sale Order Line",
|
|
|
|
ondelete="set null",
|
|
|
|
index=True,
|
2021-10-05 09:41:58 +02:00
|
|
|
copy=False,
|
2020-05-15 15:12:20 +02:00
|
|
|
)
|
|
|
|
|
2021-05-03 14:04:28 +02:00
|
|
|
sale_order_id = fields.Many2one(
|
2020-07-29 17:26:15 +02:00
|
|
|
comodel_name="sale.order",
|
|
|
|
related="sale_line_id.order_id",
|
|
|
|
string="Sales Order",
|
|
|
|
ondelete="set null",
|
|
|
|
store=True,
|
|
|
|
index=True,
|
2021-10-05 09:41:58 +02:00
|
|
|
copy=False,
|
2020-05-15 15:12:20 +02:00
|
|
|
)
|
2022-12-01 11:09:00 +01:00
|
|
|
|
|
|
|
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
|