-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
784 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
======================= | ||
Account Stock Situation | ||
======================= | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:17a4d0785da8b351798bf3c7d2b0463b8a22bf996209b21ecc9043ea00b9bfce | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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-akretion%2Fak--odoo--incubator-lightgray.png?logo=github | ||
:target: https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_stock_situation | ||
:alt: akretion/ak-odoo-incubator | ||
|
||
|badge1| |badge2| |badge3| | ||
|
||
Generate Periodically a miscellaneous account move for stock valuation with an xlsx report attachement | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
Consider to check your report before validate your account move and reverse the previous one. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/akretion/ak-odoo-incubator/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/akretion/ak-odoo-incubator/issues/new?body=module:%20account_stock_situation%0Aversion:%2016.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 | ||
~~~~~~~ | ||
|
||
* Akretion | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Akretion | ||
* David BEAL <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is part of the `akretion/ak-odoo-incubator <https://github.com/akretion/ak-odoo-incubator/tree/16.0/account_stock_situation>`_ project on GitHub. | ||
|
||
You are welcome to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 David BEAL @ akretion | ||
{ | ||
"name": "Account Stock Situation", | ||
"version": "16.0.1.0.0", | ||
"author": "Akretion", | ||
"website": "https://github.com/akretion/ak-odoo-incubator", | ||
"license": "AGPL-3", | ||
"category": "Accounting", | ||
"depends": [ | ||
"account", | ||
"stock", | ||
], | ||
"data": [ | ||
"views/config_settings.xml", | ||
"views/action.xml", | ||
], | ||
"external_dependencies": {"python": ["polars"]}, | ||
"installable": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import company | ||
from . import config_settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import base64 | ||
import io | ||
from collections import defaultdict | ||
|
||
import polars as pl | ||
|
||
from odoo import fields, models, tools | ||
from odoo.exceptions import UserError | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
valued_warehouse_ids = fields.Many2many( | ||
comodel_name="stock.warehouse", | ||
domain=lambda self: [("company_id", "=", self.env.company.id)], | ||
) | ||
stock_journal_id = fields.Many2one(comodel_name="account.journal") | ||
cost_vs_purchase_threshold = fields.Integer(string="Seuil en %") | ||
account_purchase_stock_id = fields.Many2one(comodel_name="account.account") | ||
account_stock_id = fields.Many2one(comodel_name="account.account") | ||
|
||
def _set_account_stock_valuation(self, company_string_id): | ||
self = self.env.ref(company_string_id) | ||
value, attach = self._get_stock_valuation_another() | ||
for mfield in ( | ||
"account_stock_id", | ||
"account_purchase_stock_id", | ||
"stock_journal_id", | ||
): | ||
if not self[mfield]: | ||
raise UserError( | ||
f"Le champ '{mfield}' n'est pas défini: vérifiez les " | ||
"paramètres intitulés 'Valorisation de stock'" | ||
) | ||
move = self.env["account.move"].create( | ||
{ | ||
"journal_id": self.stock_journal_id.id, | ||
"company_id": self.id, | ||
"to_check": True, | ||
"move_type": "entry", | ||
"line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"account_id": self.account_stock_id.id, | ||
"name": "stock", | ||
"debit": 0, | ||
"credit": value, | ||
}, | ||
), | ||
( | ||
0, | ||
0, | ||
{ | ||
"account_id": self.account_purchase_stock_id.id, | ||
"name": "stock", | ||
"debit": value, | ||
"credit": 0, | ||
}, | ||
), | ||
], | ||
} | ||
) | ||
attach.res_id = move.id | ||
|
||
def _get_stock_valuation_another(self): | ||
self.ensure_one() | ||
coef = self.cost_vs_purchase_threshold | ||
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url") | ||
if tools.config.get("running_env") == "dev": | ||
base_url = "http://anothercorp.localhost/" | ||
location_ids = [x.lot_stock_id.id for x in self.valued_warehouse_ids] | ||
# TODO conserver un group par emplacement : donc autant de colonnes | ||
# de nombres de produits que d'entrepots dans l'excel | ||
product_qties = self.env["stock.quant"].read_group( | ||
[("location_id", "child_of", location_ids)], | ||
["product_id", "quantity"], | ||
["product_id"], | ||
) | ||
product_ids = [x["product_id"][0] for x in product_qties] | ||
products = self.env["product.product"].browse(product_ids) | ||
prices = { | ||
x: x.variant_seller_ids and x.variant_seller_ids[0] or 0 for x in products | ||
} | ||
vals = defaultdict(list) | ||
for prd_q in product_qties: | ||
product = products.filtered(lambda s: s.id == prd_q["product_id"][0]) | ||
vals["code"].append(product.default_code) | ||
vals["designation"].append(product.name) | ||
# TODO mettre une colonne qté par entrepot (x colonnes) | ||
vals["qté"].append(round(prd_q["quantity"])) | ||
# TODO quand la valeur est < cost_vs_purchase_threshold % de ce seuil | ||
# mettre une colonne 'check' à la valeur 1 | ||
vals["valeur"].append( | ||
round( | ||
max( | ||
product.standard_price, | ||
prices[product] and prices[product].price or 0 * coef / 100, | ||
) | ||
* prd_q["quantity"] | ||
) | ||
) | ||
# TODO mettre l'url en first column | ||
vals["lien"].append( | ||
f"{base_url}/web#id={prd_q['product_id'][0]}&cids={self.id}&action=" | ||
f"{self.env.ref('product.product_normal_action_sell').id}&model=" | ||
"product.product&view_type=form" | ||
) | ||
df = pl.from_dict(vals) | ||
mfile = io.BytesIO() | ||
df.write_excel(workbook=mfile) | ||
attach = self.env["ir.attachment"].create( | ||
{ | ||
"name": "Valorisation_stock_jourdain", | ||
"type": "binary", | ||
"res_model": "account.move", | ||
"datas": base64.b64encode(mfile.getvalue()), | ||
} | ||
) | ||
return sum(vals["valeur"]), attach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
valued_warehouse_ids = fields.Many2many( | ||
related="company_id.valued_warehouse_ids", readonly=False | ||
) | ||
cost_vs_purchase_threshold = fields.Integer( | ||
related="company_id.cost_vs_purchase_threshold", readonly=False, default=120 | ||
) | ||
stock_journal_id = fields.Many2one( | ||
comodel_name="account.journal", | ||
readonly=False, | ||
related="company_id.stock_journal_id", | ||
domain=[("type", "=", "general")], | ||
) | ||
account_purchase_stock_id = fields.Many2one( | ||
comodel_name="account.account", | ||
readonly=False, | ||
related="company_id.account_purchase_stock_id", | ||
) | ||
account_stock_id = fields.Many2one( | ||
comodel_name="account.account", | ||
readonly=False, | ||
related="company_id.account_stock_id", | ||
) | ||
account_stock_help = fields.Text(compute="_compute_account_stock_help") | ||
|
||
def _compute_account_stock_help(self): | ||
for rec in self: | ||
name = "" | ||
if "l10n_fr" in self.env.registry._init_modules: | ||
name = "Compte de stock: '355...'" | ||
name += "Compte de stock d'achat: '603...'" | ||
rec.account_stock_help = name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* Akretion | ||
* David BEAL <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Generate Periodically a miscellaneous account move for stock valuation with an xlsx report attachement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Consider to check your report before validate your account move and reverse the previous one. |
Oops, something went wrong.