Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions stock_svl_vendor/README.rst
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.
2 changes: 2 additions & 0 deletions stock_svl_vendor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
16 changes: 16 additions & 0 deletions stock_svl_vendor/__manifest__.py
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",
Comment thread
nobuQuartile marked this conversation as resolved.
"maintainers": ["nobuQuartile"],
"installable": True,
}
20 changes: 20 additions & 0 deletions stock_svl_vendor/hooks.py
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
"""
)
31 changes: 31 additions & 0 deletions stock_svl_vendor/i18n/ja.po
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 "在庫移動に紐づく購買オーダの仕入先(存在する場合)。"
1 change: 1 addition & 0 deletions stock_svl_vendor/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_valuation_layer
31 changes: 31 additions & 0 deletions stock_svl_vendor/models/stock_valuation_layer.py
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

@api.depends("stock_move_id")
def _compute_vendor_id(self):
   for rec in self:
      if rec.stock_move_id.purchase_line_id.order_id:
         rec.vendor_id = rec.stock_move_id.purchase_line_id.order_id.partner_id.id

@nobuQuartile nobuQuartile Jul 14, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AungKoKoLin1997
Just to clarify, why was that again?

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?

3 changes: 3 additions & 0 deletions stock_svl_vendor/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions stock_svl_vendor/readme/DESCRIPTION.md
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.
Loading
Loading