Skip to content

Commit

Permalink
[ADD] l10n_pt_stock_vehicle_daily (16.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreispt committed Nov 16, 2024
1 parent 2c5da86 commit 9c34ed8
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 0 deletions.
33 changes: 33 additions & 0 deletions l10n_pt_stock_vehicle_daily/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Goods may be loaded and stored in a company vehicle, and not be a customer delivery or a
supplier pickup.

Examples are a travelling salesman carrying stock that might be later sold, or a
maintenance and repair technician carrying tools and spare parts.

Portuguese Tax Authorities require these to be electronically communicated every day to
their system.

This feature provides a quick way generate such document.

CONFIGURATION

- Create an Operation Type, for the vehicle daily document, of type Internal, and enable
the "Show Move On Hand Stock" checkbox.
- Create an internal Stock Location por each vehicle, and set the "License Plate" field.

USAGE

- On the Inventory Dashboard, the daily vehicle document card shows a "Move on Hand"
button at the bottom. Click on it to open an assisstant window.
- On the "Move from location" form, select the Origin Location for the Vehicle.
- The destination location will be automatically set as the same as the origin
location.
- The "License Plate" field will be automatically populated.
- The location's current stock will be selected in the lines.
- Click on "Immediate Transfer" to create the supporting transfer, or "Planned Transfer"
if changes to the stock content are needed.
- On the craeted Transfer, you can print the Delivery Slip.

CONTRIBUTORS

- Daniel Reis <dreis@opensourceintegrators.com>
2 changes: 2 additions & 0 deletions l10n_pt_stock_vehicle_daily/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizard
20 changes: 20 additions & 0 deletions l10n_pt_stock_vehicle_daily/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Transport Documents for Vehicle Stock",
"summary": "Daily documente with vehicle content, "
"to communicate to Portuguese Tax Authorities",
"website": "https://github.com/OCA/l10n-portugal",
"license": "AGPL-3",
"author": "Luz de Airbag, Open Source Integrators, Odoo Community Association (OCA)",
"category": "Warehouse",
"version": "16.0.1.0.0",
"depends": [
"stock_move_location", # from OCA/stock-logistics-warehouse
],
"data": [
"views/stock_location_views.xml",
"views/stock_picking_views.xml",
"wizard/stock_move_location_views.xml",
],
}
3 changes: 3 additions & 0 deletions l10n_pt_stock_vehicle_daily/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import stock_location
from . import stock_picking
from . import stock_picking_type
10 changes: 10 additions & 0 deletions l10n_pt_stock_vehicle_daily/models/stock_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockLocation(models.Model):
_inherit = "stock.location"

l10n_pt_license_plate = fields.Char("License Plate")
10 changes: 10 additions & 0 deletions l10n_pt_stock_vehicle_daily/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockPicking(models.Model):
_inherit = "stock.picking"

l10n_pt_license_plate = fields.Char("License Plate")
16 changes: 16 additions & 0 deletions l10n_pt_stock_vehicle_daily/models/stock_picking_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class StockPickingType(models.Model):
_inherit = "stock.picking.type"

def action_move_location(self):
action = super().action_move_location()

Check warning on line 11 in l10n_pt_stock_vehicle_daily/models/stock_picking_type.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_stock_vehicle_daily/models/stock_picking_type.py#L11

Added line #L11 was not covered by tests
# The Vehicle Locatin needs to be selected,
# So by default enable editing the location field
if self.code == "internal":
action["context"]["default_edit_locations"] = True
return action

Check warning on line 16 in l10n_pt_stock_vehicle_daily/models/stock_picking_type.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_stock_vehicle_daily/models/stock_picking_type.py#L15-L16

Added lines #L15 - L16 were not covered by tests
16 changes: 16 additions & 0 deletions l10n_pt_stock_vehicle_daily/views/stock_location_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_location_form_ext" model="ir.ui.view">
<field name="model">stock.location</field>
<field name="inherit_id" ref="stock.view_location_form" />
<field name="arch" type="xml">

<group name="additional_info" position="inside">
<field name="l10n_pt_license_plate" />
</group>

</field>
</record>

</odoo>
16 changes: 16 additions & 0 deletions l10n_pt_stock_vehicle_daily/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_picking_form_ext" model="ir.ui.view">
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form" />
<field name="arch" type="xml">

<group name="other_infos" position="inside">
<field name="l10n_pt_license_plate" />
</group>

</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions l10n_pt_stock_vehicle_daily/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_move_location
44 changes: 44 additions & 0 deletions l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class StockMoveLocationWizard(models.TransientModel):
_inherit = "wiz.stock.move.location"

@api.depends("origin_location_id", "picking_type_id")
def _compute_destination_location_id(self):
for wiz in self:
# Copy the Origin Location to the Destination Location
# If it is an Internal move and the Location has is a vehicle/has a Plate
type_is_internal = wiz.picking_type_id.code == "internal"
location_has_plate = bool(wiz.origin_location_id.l10n_pt_license_plate)

Check warning on line 16 in l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py#L15-L16

Added lines #L15 - L16 were not covered by tests
if type_is_internal and location_has_plate:
wiz.destination_location_id = wiz.origin_location_id

Check warning on line 18 in l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py#L18

Added line #L18 was not covered by tests

@api.depends("origin_location_id")
def _compute_l10n_pt_license_plate(self):
for wiz in self:
# Set the Default License Plate configured in the Location
wiz.l10n_pt_license_plate = wiz.origin_location_id.l10n_pt_license_plate

Check warning on line 24 in l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py#L24

Added line #L24 was not covered by tests

destination_location_id = fields.Many2one(
# extend to add automatic calculation
compute="_compute_destination_location_id",
store=True,
readonly=False,
)

l10n_pt_license_plate = fields.Char(
string="License Plate",
compute="_compute_l10n_pt_license_plate",
store=True,
readonly=False,
)

def _create_picking(self):
# Extend to set License Plate
picking = super()._create_picking()
picking.write({"l10n_pt_license_plate": self.l10n_pt_license_plate})
return picking

Check warning on line 44 in l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py

View check run for this annotation

Codecov / codecov/patch

l10n_pt_stock_vehicle_daily/wizard/stock_move_location.py#L42-L44

Added lines #L42 - L44 were not covered by tests
26 changes: 26 additions & 0 deletions l10n_pt_stock_vehicle_daily/wizard/stock_move_location_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_wiz_stock_move_location_form_ext" model="ir.ui.view">
<field name="model">wiz.stock.move.location</field>
<field
name="inherit_id"
ref="stock_move_location.view_wiz_stock_move_location_form_stock_move_location"
/>
<field name="arch" type="xml">

<group name="main" position="inside">
<field name="l10n_pt_license_plate" />
</group>
<!--
Opionated: Picking Type is not editable
to avoid user change it by mistake
-->
<field name="picking_type_id" position="attributes">
<attribute name="readonly">True</attribute>
</field>

</field>
</record>

</odoo>
6 changes: 6 additions & 0 deletions setup/l10n_pt_stock_vehicle_daily/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 9c34ed8

Please sign in to comment.