Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14.0 30082023 1 #8

Merged
merged 5 commits into from
Aug 30, 2023
Merged
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
26 changes: 14 additions & 12 deletions ssi_stock/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ def _assign_auto_lot_number(self):
if self.lot_name or self.lot_id:
return True

if self.product_id.categ_id.sequence_id:
sequence = self.product_id.categ_id.sequence_id
if self.move_id.date_backdating:
ctx = {"ir_sequence_date": self.move_id.date_backdating}
sequence = sequence.with_context(ctx).next_by_id()
else:
sequence = sequence.next_by_id()
self.write(
{
"lot_name": sequence,
}
)
if not self.product_id.categ_id.sequence_id:
return True

sequence = self.product_id.categ_id.sequence_id
if self.move_id.date_backdating:
ctx = {"ir_sequence_date": self.move_id.date_backdating}
number = sequence.with_context(ctx).next_by_id()
else:
number = sequence.next_by_id()
self.write(
{
"lot_name": number,
}
)
14 changes: 13 additions & 1 deletion ssi_stock/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,21 @@ class StockPicking(models.Model):
def _assign_auto_lot_number(self):
for record in self:
if record.picking_type_id.use_create_lots:
for line in record.move_line_ids:
for line in record.mapped("move_line_ids").filtered(
lambda x: (
not x.lot_id
and not x.lot_name
and x.product_id.tracking != "none"
and x.product_id.categ_id.sequence_id
and x.qty_done != 0.0
)
):
line._assign_auto_lot_number()

def _action_done(self):
self._assign_auto_lot_number()
return super()._action_done()

def button_validate(self):
self._assign_auto_lot_number()
return super().button_validate()
6 changes: 3 additions & 3 deletions ssi_stock/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<field name="inherit_id" ref="stock.vpicktree" />
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='picking_type_id']" position="after">
<field name="picking_type_category_id" />
<xpath expr="//field[@name='picking_type_id']" position="before">
<field name="picking_type_category_id" invisible="1" />
</xpath>
</data>
</field>
Expand All @@ -43,7 +43,7 @@
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='picking_type_id']" position="after">
<field name="picking_type_category_id" />
<field name="picking_type_category_id" invisible="1" />
<field
name="allowed_source_location_ids"
widget="many2many_tags"
Expand Down
10 changes: 10 additions & 0 deletions ssi_stock_account/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2022 OpenSynergy Indonesia
# Copyright 2022 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class AccountMoveLine(models.Model):
_name = "account.move.line"
_inherit = ["account.move.line"]
61 changes: 61 additions & 0 deletions ssi_stock_account/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,64 @@ class StockPicking(models.Model):
string="Journal",
comodel_name="account.journal",
)
account_move_ids = fields.Many2many(
string="Journal Entries",
comodel_name="account.move",
compute="_compute_account_move_ids",
store=False,
)
stock_valuation_layer_ids = fields.Many2many(
string="Stock Valuation Layes",
comodel_name="stock.valuation.layer",
compute="_compute_stock_valuation_layer_ids",
store=False,
)
create_accounting_entry_ok = fields.Boolean(
string="Can Create Accounting Entries",
compute="_compute_create_accounting_entry_ok",
store=False,
)

def _compute_create_accounting_entry_ok(self):
for record in self:
result = True

if record.state != "done":
result = False

if record.account_move_ids:
result = False

record.create_accounting_entry_ok = result

def _compute_account_move_ids(self):
for record in self:
result = self.env["account.move"]
for move in self.move_lines:
result += move.account_move_ids
record.account_move_ids = result

def _compute_stock_valuation_layer_ids(self):
for record in self:
result = self.env["stock.valuation.layer"]
for move in self.move_lines:
result += move.stock_valuation_layer_ids
record.stock_valuation_layer_ids = result

def action_create_accounting_entry(self):
for record in self.sudo():
record._create_accounting_entry()

def action_delete_accounting_entry(self):
for record in self.sudo():
record._delete_accounting_entry()

def _create_accounting_entry(self):
self.ensure_one()
for svl in self.stock_valuation_layer_ids:
svl._create_accounting_entry()

def _delete_accounting_entry(self):
self.ensure_one()
for svl in self.stock_valuation_layer_ids:
svl._delete_accounting_entry()
23 changes: 22 additions & 1 deletion ssi_stock_account/models/stock_valuation_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ class StockValuationLayer(models.Model):
compute="_compute_date",
store=True,
)
debit_move_line_id = fields.Many2one(
string="Debit Move Line",
comodel_name="account.move.line",
readonly=True,
)
credit_move_line_id = fields.Many2one(
string="Credit Move Line",
comodel_name="account.move.line",
readonly=True,
)

@api.depends("create_date")
def _compute_date(self):
Expand All @@ -96,7 +106,18 @@ def _create_accounting_entry(self):
return True

self._create_standard_move() # Mixin
self._create_standard_ml() # Mixin
debit_ml, credit_ml = self._create_standard_ml() # Mixin
self.write(
{
"debit_move_line_id": debit_ml.id,
"credit_move_line_id": credit_ml.id,
}
)
self.account_move_id.write(
{
"stock_move_id": self.stock_move_id.id,
}
)
self._post_standard_move() # Mixin

def _delete_accounting_entry(self):
Expand Down
21 changes: 21 additions & 0 deletions ssi_stock_account/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@
<page name="accounting" string="Accounting">
<group name="accounting_1" colspan="4" col="2">
<field name="journal_id" />
<field name="create_accounting_entry_ok" invisible="1" />
</group>
<separator string="SVL" />
<field name="stock_valuation_layer_ids" />
<separator string="Journal Entries" />
<button
name="action_create_accounting_entry"
type="object"
string="Create Accounting Entries"
icon="fa-gears"
class="oe_highlight"
attrs="{'invisible':[('create_accounting_entry_ok','=',False)]}"
/>
<button
name="action_delete_accounting_entry"
type="object"
string="Delete Accounting Entries"
icon="fa-eraser"
class="oe_highlight"
attrs="{'invisible':[('create_accounting_entry_ok','=',True)]}"
/>
<field name="account_move_ids" />
</page>
</xpath>
<xpath
Expand Down
2 changes: 2 additions & 0 deletions ssi_stock_account/views/stock_valuation_layer_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<field name="debit_account_id" />
<field name="credit_account_id" />
<field name="journal_id" />
<field name="debit_move_line_id" />
<field name="credit_move_line_id" />
</xpath>
</data>
</field>
Expand Down
6 changes: 5 additions & 1 deletion ssi_stock_fixed_asset/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"ssi_stock_account",
"ssi_fixed_asset",
],
"data": ["views/product_product_views.xml"],
"data": [
"views/product_product_views.xml",
"views/fixed_asset_asset_views.xml",
"views/stock_production_lot_views.xml",
],
"demo": [],
}
3 changes: 3 additions & 0 deletions ssi_stock_fixed_asset/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

from . import (
product_product,
fixed_asset_asset,
account_move_line,
stock_production_lot,
)
44 changes: 44 additions & 0 deletions ssi_stock_fixed_asset/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2022 OpenSynergy Indonesia
# Copyright 2022 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class AccountMoveLine(models.Model):
_name = "account.move.line"
_inherit = ["account.move.line"]

def _prepare_create_fixed_asset(self):
_super = super(AccountMoveLine, self)
result = _super._prepare_create_fixed_asset()
if self._check_fixed_asset_inventory_integration():
result.update(self._prepare_inventory_data())
return result

def _check_fixed_asset_inventory_integration(self):
self.ensure_one()

if not self.move_id.stock_move_id:
return False

stock_move = self.move_id.stock_move_id

if not stock_move.product_id.auto_create_fixed_asset:
return False

if len(stock_move.move_line_ids) > 1:
return False

return True

def _prepare_inventory_data(self):
self.ensure_one()
stock_move = self.move_id.stock_move_id
product = stock_move.product_id
stock_move_line = stock_move.move_line_ids[0]

return {
"product_id": product.id,
"lot_id": stock_move_line.lot_id.id,
}
73 changes: 73 additions & 0 deletions ssi_stock_fixed_asset/models/fixed_asset_asset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2023 OpenSynergy Indonesia
# Copyright 2023 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class FixedAssetAsset(models.Model):
_name = "fixed.asset.asset"
_inherit = ["fixed.asset.asset"]

product_id = fields.Many2one(
string="Product",
comodel_name="product.product",
)
lot_id = fields.Many2one(
string="# Serial Number",
comodel_name="stock.production.lot",
compute="_compute_lot_id",
inverse="_inverse_lot_id",
store=True,
)
lot_ids = fields.One2many(
string="Serial Numbers",
comodel_name="stock.production.lot",
inverse_name="fixed_asset_id",
)
inventory_state = fields.Selection(
string="Inventory State",
selection=[
("none", "No Link"),
("one", "Link to One Serial Number"),
("multiple", "Link to Multiple Serial Number"),
],
compute="_compute_inventory_state",
store=True,
)

@api.depends(
"lot_ids",
"lot_ids.fixed_asset_id",
"lot_id",
)
def _compute_inventory_state(self):
for record in self:
result = "none"
if len(record.lot_ids) == 1:
result = "one"
elif len(record.lot_ids) > 1:
result = "multiple"
record.inventory_state = result

@api.depends(
"lot_ids",
"lot_ids.fixed_asset_id",
)
def _compute_lot_id(self):
for record in self:
result = False
if len(record.lot_ids) == 1:
result = record.lot_ids[0]
record.lot_id = result

def _inverse_lot_id(self):
if self.lot_ids:
self.lot_ids.fixed_asset_id = False
self.lot_id.fixed_asset_id = self

@api.onchange(
"product_id",
)
def onchange_lot_id(self):
self.lot_id = False
15 changes: 15 additions & 0 deletions ssi_stock_fixed_asset/models/stock_production_lot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2022 OpenSynergy Indonesia
# Copyright 2022 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockProductionLot(models.Model):
_name = "stock.production.lot"
_inherit = ["stock.production.lot"]

fixed_asset_id = fields.Many2one(
string="Fixed Assets",
comodel_name="fixed.asset.asset",
)
Loading