[6271][ADD] stock_svl_vendor: store the vendor on stock valuation layers - #257
[6271][ADD] stock_svl_vendor: store the vendor on stock valuation layers#257nobuQuartile wants to merge 4 commits into
Conversation
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
|
Add ja.po Translation notesTranslations are referenced from existing Odoo translations where available (odoo/purchase_stock). The following terms have no reference and are translated independently:
|
| @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) |
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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).
yostashiro
left a comment
There was a problem hiding this comment.
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?
Maybe. @AungKoKoLin1997 |
|
We will create the PR in hls-oca |
|
I’ll follow up on that there. |
QT6271
Adds a
vendor_idfield tostock.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.create().pre_init_hookusing raw SQL (verified against a production-scale DB copy: 6,958/158,702 rows backfilled, zero mismatches against a join-based recomputation).