Skip to content

Commit

Permalink
Merge PR #182 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Feb 17, 2025
2 parents 675aaa1 + da3f37f commit 4fc67de
Show file tree
Hide file tree
Showing 22 changed files with 552 additions and 0 deletions.
61 changes: 61 additions & 0 deletions account_invoice_supplierinfo_update_standard_price/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
=======================================
Account Invoice - Standard Price Update
=======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:618e8f3968f6104782aaa6545901fe3d34c8482e7acf6c4372a201f557ece668
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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-grap%2Fgrap--odoo--business-lightgray.png?logo=github
:target: https://github.com/grap/grap-odoo-business/tree/12.0/account_invoice_supplierinfo_update_standard_price
:alt: grap/grap-odoo-business

|badge1| |badge2| |badge3|

It allows to update the standard price on products if the product has different
standard prices.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/grap/grap-odoo-business/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/grap/grap-odoo-business/issues/new?body=module:%20account_invoice_supplierinfo_update_standard_price%0Aversion:%2012.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
~~~~~~~

* GRAP

Contributors
~~~~~~~~~~~~

* Sylvain LE GAL (https://www.twitter.com/legalsylvain)

Maintainers
~~~~~~~~~~~

This module is part of the `grap/grap-odoo-business <https://github.com/grap/grap-odoo-business/tree/12.0/account_invoice_supplierinfo_update_standard_price>`_ project on GitHub.

You are welcome to contribute.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
27 changes: 27 additions & 0 deletions account_invoice_supplierinfo_update_standard_price/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Account Invoice - Standard Price Update",
"summary": "In the supplier invoice, automatically update all products "
"whose standard price on the line is different from "
" the product standard price",
"version": "16.0.1.0.0",
"category": "Accounting & Finance",
"author": "GRAP",
"website": "https://github.com/grap/grap-odoo-business",
"license": "AGPL-3",
"depends": [
"account_invoice_supplierinfo_update_triple_discount",
],
"data": [
"wizard/wizard_update_invoice_supplierinfo.xml",
"views/view_account_move.xml",
"views/view_product_template.xml",
],
"demo": [
"demo/product_product.xml",
],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>

<record id="transport_costs_product" model="product.product">
<field name="name">Demo Transport costs</field>
<field name="categ_id" ref="product.product_category_all"/>
<field name="uom_id" ref="uom.product_uom_unit"/>
<field name="is_impact_standard_price" eval="True"/>
</record>

</odoo>
82 changes: 82 additions & 0 deletions account_invoice_supplierinfo_update_standard_price/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_supplierinfo_update_standard_price
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-17 16:32+0000\n"
"PO-Revision-Date: 2020-12-17 16:32+0000\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_invoice_supplierinfo_update_standard_price
#: model:ir.model.fields,help:account_invoice_supplierinfo_update_standard_price.field_product_product__is_impact_standard_price
#: model:ir.model.fields,help:account_invoice_supplierinfo_update_standard_price.field_product_template__is_impact_standard_price
msgid "Check this box if you want that purchasing this product impact the standard price of the products purchased with that product.\n"
"A typical case is for Landing Cost."
msgstr "En cochant cette case, acheter ce produit impactera le coût des produits achetés conjointement à ce produit.\n"
"Cas typique d'utilisation : les frais de transports"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model.fields,field_description:account_invoice_supplierinfo_update_standard_price.field_wizard_update_invoice_supplierinfo_line__current_standard_price
msgid "Current Standard Price"
msgstr "Coût actuel"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model.fields,field_description:account_invoice_supplierinfo_update_standard_price.field_account_invoice__distributed_expense_total
msgid "Distributed Expenses Total"
msgstr "Total des charges réparties"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model.fields,field_description:account_invoice_supplierinfo_update_standard_price.field_product_product__is_impact_standard_price
#: model:ir.model.fields,field_description:account_invoice_supplierinfo_update_standard_price.field_product_template__is_impact_standard_price
msgid "Impact Standard Price"
msgstr "Impacte le coût de revient"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model,name:account_invoice_supplierinfo_update_standard_price.model_account_invoice
msgid "Invoice"
msgstr "Facture"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model,name:account_invoice_supplierinfo_update_standard_price.model_account_invoice_line
msgid "Invoice Line"
msgstr "Ligne de facture"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model.fields,field_description:account_invoice_supplierinfo_update_standard_price.field_wizard_update_invoice_supplierinfo_line__new_standard_price
msgid "New Standard Price"
msgstr "Nouveau coût"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model.fields,field_description:account_invoice_supplierinfo_update_standard_price.field_account_invoice__product_expense_total
msgid "Product Expenses Total"
msgstr "Total des charges d'articles"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model,name:account_invoice_supplierinfo_update_standard_price.model_product_template
msgid "Product Template"
msgstr "Modèle d'article"

#. module: account_invoice_supplierinfo_update_standard_price
#: code:addons/account_invoice_supplierinfo_update_standard_price/models/account_invoice_line.py:26
#, python-format
msgid "We can't check prices for a invoice whose total is null"
msgstr "On ne peut pas vérifier les prix pour une facture nulle."

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model,name:account_invoice_supplierinfo_update_standard_price.model_wizard_update_invoice_supplierinfo_line
msgid "Wizard Line to update supplierinfo"
msgstr "Line d'assistant pour mettre à jour les informations fournisseurs"

#. module: account_invoice_supplierinfo_update_standard_price
#: model:ir.model,name:account_invoice_supplierinfo_update_standard_price.model_wizard_update_invoice_supplierinfo
msgid "Wizard to update supplierinfo"
msgstr "Assistant de mise à jour des informations fournisseurs"

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import account_move
from . import account_move_line
from . import product_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (C) 2018-Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


class AccountMove(models.Model):
_inherit = "account.move"

product_expense_total = fields.Float(
string="Product Expenses Total",
compute="_compute_expense_total",
digits="Product Price",
store=True,
)

distributed_expense_total = fields.Float(
string="Distributed Expenses Total",
compute="_compute_expense_total",
digits="Product Price",
store=True,
)

@api.depends(
"invoice_line_ids.product_id.is_impact_standard_price",
"invoice_line_ids.price_subtotal",
)
def _compute_expense_total(self):
for invoice in self.filtered(lambda x: x.move_type == "in_invoice"):
invoice.update(
{
"product_expense_total": sum(
invoice.invoice_line_ids.filtered(
lambda x: not x.product_id
or not x.product_id.is_impact_standard_price
).mapped("price_subtotal")
),
"distributed_expense_total": sum(
invoice.invoice_line_ids.filtered(
lambda x: x.product_id
and x.product_id.is_impact_standard_price
).mapped("price_subtotal")
),
}
)

def _get_update_supplierinfo_lines(self):
ProductProduct = self.env["product.product"]
res = super()._get_update_supplierinfo_lines()
new_res = []
for line in res:
# Remove products that represent distributed cost
product = ProductProduct.browse(line[2]["product_id"])
if not product.is_impact_standard_price:
new_res.append(line)
return new_res
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (C) 2018-Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import _, models
from odoo.exceptions import Warning as UserError
from odoo.tools.float_utils import float_compare


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

def _get_standard_price(self):
self.ensure_one()
if not self.product_id:
return 0

if self.move_id.product_expense_total == 0:
raise UserError(
_("We can't check prices for a invoice whose total is null")
)
line_shared_cost = self.move_id.distributed_expense_total * (
self.price_subtotal / self.move_id.product_expense_total
)

if self.quantity:
line_shared_cost_per_unit = line_shared_cost / self.quantity
else:
line_shared_cost_per_unit = 0
uom = self.product_uom_id or self.product_id.uom_id
return self.move_id.currency_id.round(
uom._compute_price(
line_shared_cost_per_unit
+ (
self.price_unit
* (1 - self.discount1 / 100)
* (1 - self.discount2 / 100)
* (1 - self.discount3 / 100)
),
self.product_id.uom_id,
)
)

def _is_correct_price(self, supplierinfo):
self.ensure_one()
DecimalPrecision = self.env["decimal.precision"]
res = super()._is_correct_price(supplierinfo)
if not self.product_id:
return res

return res and not float_compare(
self.product_id.standard_price,
self._get_standard_price(),
precision_digits=DecimalPrecision.precision_get("Product Price"),
)

def _prepare_supplier_wizard_line(self, supplierinfo):
res = super()._prepare_supplier_wizard_line(supplierinfo)
if self.product_id:
res.update(
{
"current_standard_price": self.product_id.standard_price,
"new_standard_price": self._get_standard_price(),
}
)
return res
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (C) 2018-Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

is_impact_standard_price = fields.Boolean(
string="Impact Standard Price",
help="Check this box if you want"
" that purchasing this product impact the standard price of the"
" products purchased with that product.\n"
"A typical case is for Landing Cost.",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
It allows to update the standard price on products if the product has different
standard prices.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_module
Loading

0 comments on commit 4fc67de

Please sign in to comment.