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

[17.0] service maintenance: migrare modificari #1852

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions deltatech_report_prn/static/src/js/action_manager.esm.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/** @odoo-module **/
// import config from "web.config";
import {download} from "@web/core/network/download";
import {isMobileOS} from "@web/core/browser/feature_detection";
import {registry} from "@web/core/registry";

async function prnReportHandler(action, options, env) {
if (config.device.isMobile) {
if (isMobileOS()) {
return;
}
if (action.device_id) {
Expand Down
18 changes: 16 additions & 2 deletions deltatech_service_base/security/service_security.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<odoo noupdate="1">

<record id="module_category_service" model="ir.module.category">
<field name="name">Service</field>
</record>
<record id="module_category_warranty" model="ir.module.category">
<field name="name">Warranty</field>
</record>
<record id="group_service_client" model="res.groups">
<field name="name">Client</field>
<field name="category_id" ref="module_category_service" />
Expand All @@ -21,7 +24,18 @@
<field name="implied_ids" eval="[(4, ref('group_service_user'))]" />
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]" />
</record>

<record id="group_warranty_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="module_category_warranty" />
<field name="implied_ids" eval="[(4, ref('group_service_user'))]" />
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]" />
</record>
<record id="group_warranty_manager" model="res.groups">
<field name="name">Manager</field>
<field name="category_id" ref="module_category_warranty" />
<field name="implied_ids" eval="[(4, ref('group_service_user')), (4, ref('group_warranty_user'))]" />
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]" />
</record>


</odoo>
4 changes: 3 additions & 1 deletion deltatech_service_maintenance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Deltatech Services Maintenance",
"summary": "Services Maintenance",
"version": "17.0.1.1.2",
"version": "17.0.1.1.3",
"author": "Terrabit, Dorin Hongu",
"website": "https://www.terrabit.ro",
"category": "Services/Maintenance",
Expand All @@ -30,6 +30,8 @@
"views/report_notification.xml",
"views/report_order.xml",
"views/service_work_center_view.xml",
"views/service_warranty_view.xml",
"views/res_config_view.xml",
"security/ir.model.access.csv",
],
"images": ["static/description/main_screenshot.png"],
Expand Down
8 changes: 8 additions & 0 deletions deltatech_service_maintenance/data/data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<field name="number_next">1</field>
<field name="number_increment">1</field>
</record>
<record id="sequence_warranty" model="ir.sequence">
<field name="name">Warranty</field>
<field name="code">service.warranty</field>
<field name="prefix">W/%(year)s/</field>
<field name="padding">5</field>
<field name="number_next">1</field>
<field name="number_increment">1</field>
</record>
<record id="sequence_order" model="ir.sequence">
<field name="name">Service Order</field>
<field name="code">service.order</field>
Expand Down
2 changes: 2 additions & 0 deletions deltatech_service_maintenance/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
from . import service_equipment
from . import stock
from . import service_work_center
from . import service_warranty
from . import res_config_settings
13 changes: 13 additions & 0 deletions deltatech_service_maintenance/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# © 2008-2021 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

picking_type_for_warranty = fields.Many2one(
"stock.picking.type", string="Warranty picking type", config_parameter="service.picking_type_for_warranty"
)
260 changes: 260 additions & 0 deletions deltatech_service_maintenance/models/service_warranty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
# © 2015-2021 Deltatech
# Dorin Hongu <dhongu(@)gmail(.)com
# See README.rst file on addons root folder for license details


from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools.safe_eval import safe_eval

# flux garantii si reconditionari


class ServiceWarranty(models.Model):
_name = "service.warranty"
_description = "Warranty"
_inherit = ["mail.thread", "mail.activity.mixin"]

type = fields.Selection([("warranty", "Warranty"), ("recondition", "Recondition")])
name = fields.Char(string="Reference", readonly=True, index=True, default="/", copy=False)
date = fields.Datetime(
string="Date",
default=fields.Date.context_today,
readonly=True,
)
state = fields.Selection(
[
("new", "New"),
("assigned", "Assigned"),
("progress", "In Progress"),
("approval_requested", "Approval requested"),
("approved", "Approved"),
("done", "Done"),
],
default="new",
string="Status",
tracking=True,
)

rec_state = fields.Selection(
[
("new", "New"),
("progress", "In Progress"),
("done", "Done"),
],
default="new",
string="Status",
tracking=True,
)

clarifications_state = fields.Selection(
[("required", "Required"), ("sent", "Sent")], string="Clarifications", tracking=True
)
equipment_id = fields.Many2one(
"service.equipment",
string="Equipment",
index=True,
readonly=True,
)
partner_id = fields.Many2one("res.partner", string="Customer")
has_agreement = fields.Boolean("Has service agreement", compute="_compute_service_agreement")
user_id = fields.Many2one("res.users", string="Responsible")
description = fields.Text("Notes", readonly=False)
picking_id = fields.Many2one("stock.picking", string="Consumables", copy=False)
sale_order_id = fields.Many2one("sale.order", string="Sale Order")
invoice_id = fields.Many2one("account.move", string="Invoice")
item_ids = fields.One2many(
"service.warranty.item",
"warranty_id",
string="Warranty Lines",
readonly=False,
copy=True,
)
total_amount = fields.Float(string="Total amount", compute="_compute_total_amount", store=True)

def _compute_service_agreement(self):
agreements_installed = (
self.env["ir.module.module"]
.sudo()
.search([("name", "=", "deltatech_service_agreement"), ("state", "=", "installed")])
)
for warranty in self:
if not agreements_installed or not warranty.partner_id:
warranty.has_agreement = False
else:
query = """
SELECT id, state FROM service_agreement agr
WHERE
state IN %(states)s
AND partner_id IN %(partners)s
"""
params = {
"partners": tuple([warranty.partner_id.id, warranty.partner_id.commercial_partner_id.id]),
"states": tuple(["draft", "open"]),
}
self.env.cr.execute(query, params=params)
res = self.env.cr.dictfetchall()
if res:
warranty.has_agreement = True
else:
warranty.has_agreement = False

@api.depends("item_ids")
def _compute_total_amount(self):
for warranty in self:
total_amount = 0.0
for line in warranty.item_ids:
total_amount += line.amount
warranty.total_amount = total_amount

@api.onchange("equipment_id")
def onchange_equipment_id(self):
if self.equipment_id:
self.user_id = self.equipment_id.technician_user_id or self.user_id
if self.equipment_id.serial_id:
move_lines = (
self.env["stock.move.line"]
.sudo()
.search(
[
("lot_id", "=", self.equipment_id.serial_id.id),
("state", "=", "done"),
("product_id", "=", self.equipment_id.product_id.id),
],
order="date DESC",
)
)
if move_lines:
last_move = False
if move_lines[0].location_dest_id.usage == "customer":
# if last move seems like a delivery
last_move = move_lines[0]
else:
for move in move_lines:
if move.location_dest_id.usage == "customer":
last_move = move
break
if last_move and last_move.sudo().move_id.sale_line_id:
self.sudo().sale_order_id = last_move.move_id.sudo().sale_line_id.order_id
invoice_lines = last_move.move_id.sudo().sale_line_id.invoice_lines
invoices = invoice_lines.sudo().move_id
if len(invoices.sudo()) == 1:
if invoices.sudo().state == "posted" and invoices.sudo().move_type == "out_invoice":
self.invoice_id = invoices.sudo()
self.partner_id = invoices.partner_id
else:
self.invoice_id = False
self.sale_order_id = False
self.partner_id = False

def new_delivery_button(self):
# block picking if partner blocked
if self.partner_id:
if self.partner_id.picking_warn == "block":
raise UserError(self.partner_id.picking_warn_msg)
if self.partner_id.parent_id:
if self.partner_id.parent_id.picking_warn == "block":
raise UserError(self.partner_id.parent_id.picking_warn_msg)

get_param = self.env["ir.config_parameter"].sudo().get_param
picking_type_id = safe_eval(get_param("service.picking_type_for_warranty", "False"))
if picking_type_id:
picking_type = self.env["stock.picking.type"].browse(picking_type_id)
else:
raise UserError(_("Please set a warranty picking type in settings"))

# context = self.get_context_default()
context = dict(self.env.context)
context.update(
{
"default_origin": self.name,
"default_picking_type_code": "outgoing",
"default_picking_type_id": picking_type_id,
"default_partner_id": self.partner_id.id,
}
)

if self.item_ids:
context["default_move_ids_without_package"] = []

for item in self.item_ids:
value = {
"name": item.product_id.name,
"product_id": item.product_id.id,
"product_uom": item.product_id.uom_id.id,
"product_uom_qty": item.quantity,
"location_id": picking_type.default_location_src_id.id,
"location_dest_id": picking_type.default_location_dest_id.id,
"price_unit": item.product_id.standard_price,
}
context["default_move_ids_without_package"] += [(0, 0, value)]
context["warranty_id"] = self.id
return {
"name": _("Delivery for warranty"),
"view_type": "form",
"view_mode": "form",
"res_model": "stock.picking",
"view_id": False,
"views": [[False, "form"]],
"context": context,
"type": "ir.actions.act_window",
}

@api.onchange("user_id")
def set_assigned(self):
if self.state == "new" and self.user_id:
self.state = "assigned"

def set_new(self):
if self.state == "assigned":
self.state = "new"
self.user_id = False

def set_in_progress(self):
if self.state == "assigned" and self.user_id:
self.state = "progress"

def request_approval(self):
self.state = "approval_requested"

def approve(self):
self.state = "approved"

def set_done(self):
self.state = "done"

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if "name" not in vals or ("name" in vals and vals["name"] == "/"):
vals["name"] = self.env["ir.sequence"].next_by_code("service.warranty")
return super().create(vals_list)


class ServiceWarrantyItem(models.Model):
_name = "service.warranty.item"
_description = "Warranty Item"
_order = "warranty_id, sequence, id"

sequence = fields.Integer(string="Sequence", default=10)
name = fields.Char("Name")
warranty_id = fields.Many2one(
"service.warranty", string="Warranty", readonly=True, index=True, required=True, ondelete="cascade"
)
product_id = fields.Many2one("product.product", string="Product")
alternative_code = fields.Char(related="product_id.alternative_code")
quantity = fields.Float(string="Quantity", digits="Product Unit of Measure", default=1)
product_uom = fields.Many2one("uom.uom", string="Unit of Measure ")
note = fields.Char(string="Note")
price_unit = fields.Float(string="Unit price")
amount = fields.Float(string="Amount", compute="_compute_amount")

@api.onchange("product_id")
def onchange_product_id(self):
self.product_uom = self.product_id.uom_id
self.name = self.product_id.name
self.price_unit = self.product_id.standard_price

def _compute_amount(self):
for line in self:
line.amount = line.price_unit * line.quantity
Loading
Loading