Skip to content

[6271][ADD] stock_svl_vendor: store the vendor on stock valuation layers - #257

Closed
nobuQuartile wants to merge 4 commits into
18.0from
6271-add-stock_svl_vendor
Closed

[6271][ADD] stock_svl_vendor: store the vendor on stock valuation layers#257
nobuQuartile wants to merge 4 commits into
18.0from
6271-add-stock_svl_vendor

Conversation

@nobuQuartile

@nobuQuartile nobuQuartile commented Jul 10, 2026

Copy link
Copy Markdown

QT6271

Adds a vendor_id field to stock.valuation.layer, populated from the purchase order linked to the stock move (stock_move_id.purchase_line_id.order_id.partner_id), so valuation layers can be filtered/reported on by vendor without joining through the move and purchase order each time.

  • New records: computed in an overridden create().
  • Existing records: backfilled via pre_init_hook using raw SQL (verified against a production-scale DB copy: 6,958/158,702 rows backfilled, zero mismatches against a join-based recomputation).

The vendor of the purchase order linked to a stock move is set on the
resulting stock.valuation.layer at creation time, so valuation layers
can be filtered/reported on by vendor without joining through the
stock move and purchase order each time. Existing rows are backfilled
via a pre_init_hook.

task-6271
@nobuQuartile
nobuQuartile marked this pull request as draft July 13, 2026 02:32
@nobuQuartile

Copy link
Copy Markdown
Author

Add ja.po

Translation notes

Translations are referenced from existing Odoo translations where available (odoo/purchase_stock).

The following terms have no reference and are translated independently:

msgid msgstr
Vendor of the purchase order linked to the stock move, if any. 在庫移動に紐づく購買オーダの仕入先(存在する場合)。

Comment on lines +18 to +31
@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)

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?

Comment thread stock_svl_vendor/__manifest__.py

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.

If I understand the background of this module correctly, customer wants to consolidate the SVL amount per vendor. So, please add vendor field in the search view (search, groupby).

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

Thank you! That's true.

@yostashiro yostashiro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Haven't reviewed the content of the module but the module name doesn't look optimal. Please consider changing it to stock_valuation_layer_vendor.

Is this not an OCA candidate?

@nobuQuartile

Copy link
Copy Markdown
Author

Is this not an OCA candidate?

Maybe.

@AungKoKoLin1997
Could you create the PR in OCA and follow up on updating the code?

@nobuQuartile

Copy link
Copy Markdown
Author

We will create the PR in hls-oca

@nobuQuartile

Copy link
Copy Markdown
Author

I’ll follow up on that there.
qrtl/hls-oca#166

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants