Skip to content

Commit 361ac67

Browse files
committed
[ENH] Scrap: back date
1 parent d49ebcc commit 361ac67

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

stock_move_backdating/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"views/stock_quant_views.xml",
2323
"views/stock_picking_views.xml",
2424
"views/stock_move_line_views.xml",
25+
"views/stock_scrap_views.xml",
2526
],
2627
"installable": True,
2728
}

stock_move_backdating/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
from . import stock_move_line
55
from . import stock_picking
66
from . import stock_quant
7+
from . import stock_scrap

stock_move_backdating/models/stock_move.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _get_price_unit(self):
4242

4343
def _backdating_account_moves(self):
4444
"""Set date on linked account.move same for each move in `self`."""
45-
picking_account_moves = self.env["account.move"].search(
45+
picking_account_moves = self.env["account.move"].sudo().search(
4646
[
4747
("stock_move_id", "in", self.ids),
4848
],
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright 2024 Ecosoft Co., Ltd. (http://ecosoft.co.th)
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import Command, api, fields, models
5+
from .stock_move_line import check_date
6+
7+
8+
class StockScrap(models.Model):
9+
_inherit = "stock.scrap"
10+
11+
date_backdating = fields.Datetime(
12+
string="Forced Effective Date",
13+
copy=False,
14+
help="The Actual Movement Date of the Operations "
15+
"only if they have all the same value.",
16+
)
17+
18+
@api.onchange("date_backdating")
19+
def onchange_date_backdating(self):
20+
self.ensure_one()
21+
check_date(self.date_backdating)
22+
23+
def _prepare_move_values(self):
24+
"""Update backdating into stock move line"""
25+
self.ensure_one()
26+
move_dict = super()._prepare_move_values()
27+
move_dict["move_line_ids"][0][2]["date_backdating"] = self.date_backdating
28+
return move_dict
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<odoo>
2+
<record id="stock_scrap_form_view" model="ir.ui.view">
3+
<field name="name">stock.scrap.form</field>
4+
<field name="model">stock.scrap</field>
5+
<field name="inherit_id" ref="stock.stock_scrap_form_view" />
6+
<field name="arch" type="xml">
7+
<xpath expr="//field[@name='date_done']" position="before">
8+
<field name="date_backdating" attrs="{'readonly': [('state', '!=', 'draft')]}" />
9+
</xpath>
10+
</field>
11+
</record>
12+
</odoo>

0 commit comments

Comments
 (0)