Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
2
account_invoice_supplierinfo_update/models/__init__.py
Normal file
2
account_invoice_supplierinfo_update/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import account_move
|
||||
from . import account_move_line
|
||||
86
account_invoice_supplierinfo_update/models/account_move.py
Normal file
86
account_invoice_supplierinfo_update/models/account_move.py
Normal file
@@ -0,0 +1,86 @@
|
||||
# Copyright 2016 Chafique DELLI @ Akretion
|
||||
# Copyright 2016-Today: GRAP (http://www.grap.coop)
|
||||
# Copyright Sylvain LE GAL (https://twitter.com/legalsylvain)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
from odoo import Command, fields, models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = "account.move"
|
||||
|
||||
# Column Section
|
||||
supplier_partner_id = fields.Many2one(
|
||||
comodel_name="res.partner",
|
||||
string="Supplier Partner",
|
||||
compute="_compute_supplier_partner_id",
|
||||
)
|
||||
|
||||
supplierinfo_ok = fields.Boolean(
|
||||
string="Supplier Informations Checked",
|
||||
copy=False,
|
||||
help="Checked if the check of supplierinfo has been done.\n"
|
||||
" - Uncheck this box, if you want to check again this invoice\n"
|
||||
" - Check this box, if you want to mark this invoice as checked",
|
||||
)
|
||||
|
||||
# Compute Section
|
||||
def _compute_supplier_partner_id(self):
|
||||
for invoice in self:
|
||||
invoice.supplier_partner_id = (
|
||||
invoice.partner_id.commercial_partner_id or invoice.partner_id
|
||||
)
|
||||
|
||||
# Custom Section
|
||||
def _get_update_supplierinfo_lines(self):
|
||||
self.ensure_one()
|
||||
lines = []
|
||||
product_ids = []
|
||||
|
||||
for line in self.invoice_line_ids.filtered(lambda x: x.product_id):
|
||||
# We the invoice has two or more lines with the same product,
|
||||
# the computation will be based only on the first line.
|
||||
if line.product_id.id in product_ids:
|
||||
continue
|
||||
|
||||
product_ids.append(line.product_id.id)
|
||||
|
||||
# Get supplierinfo if exist
|
||||
supplierinfo = line._get_supplierinfo()
|
||||
|
||||
# Test if supplierinfo matches with line info
|
||||
if supplierinfo:
|
||||
if line._is_matching_supplierinfo(supplierinfo):
|
||||
continue
|
||||
|
||||
# Propose updating, if needed
|
||||
lines.append(
|
||||
Command.create(line._prepare_supplier_wizard_line(supplierinfo))
|
||||
)
|
||||
return lines
|
||||
|
||||
# View Section
|
||||
def check_supplierinfo(self):
|
||||
self.ensure_one()
|
||||
lines_for_update = self._get_update_supplierinfo_lines()
|
||||
if lines_for_update:
|
||||
ctx = {
|
||||
"default_line_ids": lines_for_update,
|
||||
"default_invoice_id": self.id,
|
||||
}
|
||||
|
||||
view_form = self.env.ref(
|
||||
"account_invoice_supplierinfo_update."
|
||||
"view_wizard_update_invoice_supplierinfo_form"
|
||||
)
|
||||
return {
|
||||
"name": self.env._("Update supplier informations of products"),
|
||||
"type": "ir.actions.act_window",
|
||||
"view_mode": "form",
|
||||
"res_model": "wizard.update.invoice.supplierinfo",
|
||||
"views": [(view_form.id, "form")],
|
||||
"view_id": view_form.id,
|
||||
"target": "new",
|
||||
"context": ctx,
|
||||
}
|
||||
else:
|
||||
self.write({"supplierinfo_ok": True})
|
||||
@@ -0,0 +1,50 @@
|
||||
# © 2016 Chafique DELLI @ Akretion
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import models
|
||||
from odoo.tools import float_compare
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = "account.move.line"
|
||||
|
||||
def _get_supplierinfo(self):
|
||||
"""Given an invoice line, return the supplierinfo that matches
|
||||
with product and supplier, if exist"""
|
||||
self.ensure_one()
|
||||
supplierinfos = self.product_id.seller_ids.filtered(
|
||||
lambda seller: seller.partner_id == self.move_id.supplier_partner_id
|
||||
)
|
||||
return supplierinfos and supplierinfos[0] or False
|
||||
|
||||
def _is_matching_supplierinfo(self, supplierinfo):
|
||||
"""Return True if the partner information matches with line information"""
|
||||
self.ensure_one()
|
||||
res = (
|
||||
not self.product_uom_id or self.product_uom_id == supplierinfo.product_uom
|
||||
) and not float_compare(
|
||||
self.price_unit,
|
||||
supplierinfo.price,
|
||||
precision_rounding=self.move_id.currency_id.rounding,
|
||||
)
|
||||
precision = self.env["decimal.precision"].precision_get("Discount")
|
||||
return res and not float_compare(
|
||||
self.discount, supplierinfo.discount, precision_digits=precision
|
||||
)
|
||||
|
||||
def _prepare_supplier_wizard_line(self, supplierinfo):
|
||||
"""Prepare the value that will proposed to user in the wizard
|
||||
to update supplierinfo"""
|
||||
self.ensure_one()
|
||||
return {
|
||||
"product_id": self.product_id.id,
|
||||
"supplierinfo_id": supplierinfo and supplierinfo.id or False,
|
||||
"current_price": supplierinfo and supplierinfo.price or False,
|
||||
"new_price": self.price_unit,
|
||||
"current_uom_id": supplierinfo and supplierinfo.product_uom.id or False,
|
||||
"new_uom_id": self.product_uom_id.id or self.product_id.uom_po_id.id,
|
||||
"current_min_quantity": supplierinfo and supplierinfo.min_qty or False,
|
||||
"new_min_quantity": supplierinfo and supplierinfo.min_qty or False,
|
||||
"current_discount": supplierinfo and supplierinfo.discount,
|
||||
"new_discount": self.discount,
|
||||
}
|
||||
Reference in New Issue
Block a user