-
Notifications
You must be signed in to change notification settings - Fork 9
[6271][ADD] stock_svl_vendor: store the vendor on stock valuation layers #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5fc106f
84da3f3
f4d9279
7b91635
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| ============================ | ||
| Stock Valuation Layer Vendor | ||
| ============================ | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:7bb64c277e472c06137f6cf7274c16963ef0a6e00a2a837a9f8cf2dcd5a06433 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |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-qrtl%2Fhls--custom-lightgray.png?logo=github | ||
| :target: https://github.com/qrtl/hls-custom/tree/18.0/stock_svl_vendor | ||
| :alt: qrtl/hls-custom | ||
|
|
||
| |badge1| |badge2| |badge3| | ||
|
|
||
| This module adds a vendor field to stock valuation layers, populated | ||
| from the purchase order linked to the related stock move. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/qrtl/hls-custom/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/qrtl/hls-custom/issues/new?body=module:%20stock_svl_vendor%0Aversion:%2018.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 | ||
| ------- | ||
|
|
||
| * Quartile | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| .. |maintainer-nobuQuartile| image:: https://github.com/nobuQuartile.png?size=40px | ||
| :target: https://github.com/nobuQuartile | ||
| :alt: nobuQuartile | ||
|
|
||
| Current maintainer: | ||
|
|
||
| |maintainer-nobuQuartile| | ||
|
|
||
| This module is part of the `qrtl/hls-custom <https://github.com/qrtl/hls-custom/tree/18.0/stock_svl_vendor>`_ 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 .hooks import pre_init_hook |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Copyright 2026 Quartile (https://www.quartile.co) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
| { | ||
| "name": "Stock Valuation Layer Vendor", | ||
| "summary": "Store the vendor on stock valuation layers created from purchases.", | ||
| "version": "18.0.1.0.0", | ||
| "author": "Quartile", | ||
| "website": "https://www.quartile.co", | ||
| "category": "Inventory", | ||
| "license": "AGPL-3", | ||
| "depends": ["purchase_stock"], | ||
| "data": ["views/stock_valuation_layer_views.xml"], | ||
| "pre_init_hook": "pre_init_hook", | ||
| "maintainers": ["nobuQuartile"], | ||
| "installable": True, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 2026 Quartile (https://www.quartile.co) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo.tools.sql import column_exists, create_column | ||
|
|
||
|
|
||
| def pre_init_hook(env): | ||
| if column_exists(env.cr, "stock_valuation_layer", "vendor_id"): | ||
| return | ||
| create_column(env.cr, "stock_valuation_layer", "vendor_id", "int4") | ||
| env.cr.execute( | ||
| """ | ||
| UPDATE stock_valuation_layer svl | ||
| SET vendor_id = po.partner_id | ||
| FROM stock_move sm | ||
| JOIN purchase_order_line pol ON pol.id = sm.purchase_line_id | ||
| JOIN purchase_order po ON po.id = pol.order_id | ||
| WHERE svl.stock_move_id = sm.id | ||
| """ | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Translation of Odoo Server. | ||
| # This file contains the translation of the following modules: | ||
| # * stock_svl_vendor | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Odoo Server 18.0+e\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "POT-Creation-Date: 2026-07-13 04:11+0000\n" | ||
| "PO-Revision-Date: 2026-07-13 04:11+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: stock_svl_vendor | ||
| #: model:ir.model,name:stock_svl_vendor.model_stock_valuation_layer | ||
| msgid "Stock Valuation Layer" | ||
| msgstr "在庫評価レイヤ" | ||
|
|
||
| #. module: stock_svl_vendor | ||
| #: model:ir.model.fields,field_description:stock_svl_vendor.field_stock_valuation_layer__vendor_id | ||
| msgid "Vendor" | ||
| msgstr "仕入先" | ||
|
|
||
| #. module: stock_svl_vendor | ||
| #: model:ir.model.fields,help:stock_svl_vendor.field_stock_valuation_layer__vendor_id | ||
| msgid "Vendor of the purchase order linked to the stock move, if any." | ||
| msgstr "在庫移動に紐づく購買オーダの仕入先(存在する場合)。" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import stock_valuation_layer |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Copyright 2026 Quartile (https://www.quartile.co) | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import api, fields, models | ||
|
|
||
|
|
||
| class StockValuationLayer(models.Model): | ||
| _inherit = "stock.valuation.layer" | ||
|
|
||
| vendor_id = fields.Many2one( | ||
| "res.partner", | ||
| string="Vendor", | ||
| readonly=True, | ||
| index=True, | ||
| help="Vendor of the purchase order linked to the stock move, if any.", | ||
| ) | ||
|
|
||
| @api.model_create_multi | ||
| def create(self, vals_list): | ||
| move_ids = { | ||
| vals["stock_move_id"] for vals in vals_list if vals.get("stock_move_id") | ||
| } | ||
| vendor_by_move = { | ||
| move.id: move.purchase_line_id.order_id.partner_id.id | ||
| for move in self.env["stock.move"].browse(move_ids) | ||
| } | ||
| for vals in vals_list: | ||
| vendor_id = vendor_by_move.get(vals.get("stock_move_id")) | ||
| if vendor_id: | ||
| vals["vendor_id"] = vendor_id | ||
| return super().create(vals_list) | ||
|
Comment on lines
+18
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nobuQuartile Instead of working on create method, I believe using stored compute field will be better.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AungKoKoLin1997 I thought the idea was that if a field is intended to be initialized only once at creation time and remain unchanged afterward, we should set it in the create() method rather than using a stored computed field. Am I remembering that correctly? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| This module adds a vendor field to stock valuation layers, populated from the | ||
| purchase order linked to the related stock move. |
Uh oh!
There was an error while loading. Please reload this page.