Skip to content

Commit

Permalink
[16.0][3825][IMP] stock_picking_accounting_date, stock_valuation_laye…
Browse files Browse the repository at this point in the history
…r_accounting… (#86)

* [IMP] stock_picking_accounting_date, stock_valuation_layer_accounting_date
  • Loading branch information
AungKoKoLin1997 authored Nov 7, 2023
1 parent 2d251d7 commit 78a0dd6
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 8 deletions.
1 change: 1 addition & 0 deletions stock_picking_accounting_date/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"license": "AGPL-3",
"depends": ["stock_account"],
"data": [
"views/stock_move_views.xml",
"views/stock_picking_views.xml",
],
"installable": True,
Expand Down
18 changes: 15 additions & 3 deletions stock_picking_accounting_date/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# Copyright 2023 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models
from odoo import api, fields, models


class StockMove(models.Model):
_inherit = "stock.move"

accounting_date = fields.Date(
compute="_compute_accounting_date",
store=True,
)

@api.depends("date", "accounting_date")
def _compute_accounting_date(self):
for line in self:
line.accounting_date = fields.Datetime.context_timestamp(self, line.date)
if line.picking_id.accounting_date:
line.accounting_date = line.picking_id.accounting_date

def _prepare_account_move_vals(
self,
credit_account_id,
Expand All @@ -26,6 +38,6 @@ def _prepare_account_move_vals(
svl_id,
cost,
)
if self.picking_id.accounting_date:
am_vals.update({"date": self.picking_id.accounting_date})
if self.accounting_date:
am_vals.update({"date": self.accounting_date})
return am_vals
1 change: 0 additions & 1 deletion stock_picking_accounting_date/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class StockPicking(models.Model):
_inherit = "stock.picking"

accounting_date = fields.Date(
states={"done": [("readonly", True)], "cancel": [("readonly", True)]},
help="Accounting date for stock valuation journal entry.",
)
show_accounting_date = fields.Boolean(compute="_compute_show_accounting_date")
Expand Down
7 changes: 5 additions & 2 deletions stock_picking_accounting_date/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
This module adds accounting date in picking and pass the value to accounting date
of SVL's journal entry.
This module adds an accounting date in both stock pickings and stock moves.
The accounting date from the picking is propagated to its corresponding stock move.
If a picking doesn't specify an accounting date, the stock move's accounting date
will be set to the 'Effective Date'. This value is then passed to the SVL's journal entry
accounting date.
13 changes: 13 additions & 0 deletions stock_picking_accounting_date/views/stock_move_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_move_tree_acceptance_date_inherit" model="ir.ui.view">
<field name="name">stock.move.tree</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_move_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='reference']" position="before">
<field name="accounting_date" optional="show" />
</xpath>
</field>
</record>
</odoo>
7 changes: 6 additions & 1 deletion stock_picking_accounting_date/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
<field name="arch" type="xml">
<xpath expr="//label[@for='scheduled_date']" position="before">
<field name="show_accounting_date" invisible="1" />
<!-- To Do: remove this updates and set the readonly as the original (on stock_picking.py)
once the stock_picking_consumable has prepared the computed field to make accounting_date
readonly when the item on transfer is consumable product -->
<field
name="accounting_date"
attrs="{'invisible': [('show_accounting_date', '=', False)]}"
attrs="{'invisible': [('show_accounting_date', '=', False)],
'readonly': [('show_accounting_date', '=', True),
('state', 'in', ('done', 'cancel'))]}"
/>
</xpath>
</field>
Expand Down
2 changes: 1 addition & 1 deletion stock_valuation_layer_accounting_date/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Quartile Limited, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"license": "AGPL-3",
"depends": ["stock_account"],
"depends": ["stock_picking_accounting_date"],
"data": [
"views/stock_valuation_layer_views.xml",
"wizard/stock_quantity_history.xml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def _compute_accounting_date(self):
if account_move and account_move.state == "posted":
rec.accounting_date = account_move.date
continue
if rec.stock_move_id:
rec.accounting_date = rec.stock_move_id.accounting_date
continue
rec.accounting_date = fields.Datetime.context_timestamp(
self, rec.create_date
)

0 comments on commit 78a0dd6

Please sign in to comment.