mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms: add multiple sale channel in pms_service and pms_service_line
This commit is contained in:
committed by
Darío Lodeiros
parent
1d22a5c4e9
commit
a892096aca
@@ -146,17 +146,19 @@ class PmsService(models.Model):
|
||||
("no", "Nothing to Invoice"),
|
||||
],
|
||||
)
|
||||
channel_type = fields.Selection(
|
||||
string="Sales Channel",
|
||||
help="sales channel through which the service was sold."
|
||||
"It can be 'door', 'mail', 'phone', 'call' or 'web'",
|
||||
selection=[
|
||||
("door", "Door"),
|
||||
("mail", "Mail"),
|
||||
("phone", "Phone"),
|
||||
("call", "Call Center"),
|
||||
("web", "Web"),
|
||||
],
|
||||
sale_channel_ids = fields.Many2many(
|
||||
string="Sale Channels",
|
||||
help="Sale Channels through which service lines were managed",
|
||||
store=True,
|
||||
compute="_compute_sale_channel_ids",
|
||||
comodel_name="pms.sale.channel",
|
||||
check_pms_properties=True,
|
||||
)
|
||||
sale_channel_origin_id = fields.Many2one(
|
||||
string="Sale Channel Origin",
|
||||
help="Sale Channel through which service was created, the original",
|
||||
comodel_name="pms.sale.channel",
|
||||
check_pms_properties=True,
|
||||
)
|
||||
price_subtotal = fields.Monetary(
|
||||
string="Subtotal",
|
||||
@@ -425,6 +427,13 @@ class PmsService(models.Model):
|
||||
line.discount = record.discount
|
||||
line.cancel_discount = 0
|
||||
|
||||
@api.depends("service_line_ids", "service_line_ids.sale_channel_id")
|
||||
def _compute_sale_channel_ids(self):
|
||||
for record in self:
|
||||
record.sale_channel_ids = [
|
||||
(6, 0, record.mapped("service_line_ids.sale_channel_id.id"))
|
||||
]
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
for rec in self:
|
||||
@@ -534,3 +543,60 @@ class PmsService(models.Model):
|
||||
)
|
||||
else:
|
||||
return 0
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get("reservation_id") and not vals.get("sale_channel_origin_id"):
|
||||
reservation = self.env["pms.reservation"].browse(vals["reservation_id"])
|
||||
if reservation.sale_channel_origin_id:
|
||||
vals["sale_channel_origin_id"] = reservation.sale_channel_origin_id.id
|
||||
elif (
|
||||
vals.get("folio_id")
|
||||
and not vals.get("reservation_id")
|
||||
and not vals.get("sale_channel_origin_id")
|
||||
):
|
||||
folio = self.env["pms.folio"].browse(vals["folio_id"])
|
||||
if folio.sale_channel_origin_id:
|
||||
vals["sale_channel_origin_id"] = folio.sale_channel_origin_id.id
|
||||
record = super(PmsService, self).create(vals)
|
||||
return record
|
||||
|
||||
def write(self, vals):
|
||||
folios_to_update_channel = self.env["pms.folio"]
|
||||
lines_to_update_channel = self.env["pms.service.line"]
|
||||
if "sale_channel_origin_id" in vals:
|
||||
folios_to_update_channel = self.get_folios_to_update_channel(vals)
|
||||
lines_to_update_channel = self.get_service_lines_to_update_channel(vals)
|
||||
res = super(PmsService, self).write(vals)
|
||||
if folios_to_update_channel:
|
||||
folios_to_update_channel.sale_channel_origin_id = vals[
|
||||
"sale_channel_origin_id"
|
||||
]
|
||||
if lines_to_update_channel:
|
||||
lines_to_update_channel.sale_channel_id = vals["sale_channel_origin_id"]
|
||||
return res
|
||||
|
||||
def get_folios_to_update_channel(self, vals):
|
||||
folios_to_update_channel = self.env["pms.folio"]
|
||||
for folio in self.mapped("folio_id"):
|
||||
if (
|
||||
any(
|
||||
service.sale_channel_origin_id == folio.sale_channel_origin_id
|
||||
for service in self.filtered(lambda r: r.folio_id == folio)
|
||||
)
|
||||
and vals["sale_channel_origin_id"] != folio.sale_channel_origin_id.id
|
||||
and (len(folio.reservation_ids) == 0)
|
||||
and (len(folio.service_ids) == 1)
|
||||
):
|
||||
folios_to_update_channel += folio
|
||||
return folios_to_update_channel
|
||||
|
||||
def get_service_lines_to_update_channel(self, vals):
|
||||
lines_to_update_channel = self.env["pms.service.line"]
|
||||
for record in self:
|
||||
for service_line in record.service_line_ids:
|
||||
if service_line.sale_channel_id == self.sale_channel_origin_id and (
|
||||
vals["sale_channel_origin_id"] != service_line.sale_channel_id.id
|
||||
):
|
||||
lines_to_update_channel += service_line
|
||||
return lines_to_update_channel
|
||||
|
||||
@@ -126,6 +126,12 @@ class PmsServiceLine(models.Model):
|
||||
readonly=True,
|
||||
store=True,
|
||||
)
|
||||
sale_channel_id = fields.Many2one(
|
||||
string="Sale Channel",
|
||||
help="Sale Channel through which service line was created",
|
||||
comodel_name="pms.sale.channel",
|
||||
check_pms_properties=True,
|
||||
)
|
||||
auto_qty = fields.Boolean(
|
||||
string="Qty automated setted",
|
||||
help="Show if the day qty was calculated automatically",
|
||||
@@ -249,6 +255,15 @@ class PmsServiceLine(models.Model):
|
||||
% (record.service_id.product_id.name, record.date)
|
||||
)
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if vals.get("service_id") and not vals.get("sale_channel_id"):
|
||||
service = self.env["pms.service"].browse(vals["service_id"])
|
||||
if service.sale_channel_origin_id:
|
||||
vals["sale_channel_id"] = service.sale_channel_origin_id.id
|
||||
record = super(PmsServiceLine, self).create(vals)
|
||||
return record
|
||||
|
||||
# Business methods
|
||||
def _cancel_discount(self):
|
||||
for record in self:
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<field name="product_id" />
|
||||
<field name="day_qty" />
|
||||
<field name="date" />
|
||||
<field name="sale_channel_id" />
|
||||
<field name="price_unit" />
|
||||
<field
|
||||
name="discount"
|
||||
@@ -29,6 +30,7 @@
|
||||
<field name="product_id" />
|
||||
<field name="day_qty" />
|
||||
<field name="date" />
|
||||
<field name="sale_channel_id" />
|
||||
<field name="price_unit" />
|
||||
<field
|
||||
name="discount"
|
||||
|
||||
@@ -27,7 +27,10 @@
|
||||
attrs="{'readonly': [('per_day','=',True)]}"
|
||||
force_save="1"
|
||||
/>
|
||||
<field name="sale_channel_origin_id" />
|
||||
<field name="sale_channel_ids" widget="many2many_tags" />
|
||||
</group>
|
||||
|
||||
<field name="tax_ids" widget="many2many_tags" invisible="1" />
|
||||
<field name="price_subtotal" invisible="1" />
|
||||
<field name="price_tax" invisible="1" />
|
||||
@@ -35,6 +38,7 @@
|
||||
<field name="service_line_ids" nolabel="1">
|
||||
<tree string="Days" editable="bottom">
|
||||
<field name="date" />
|
||||
<field name="sale_channel_id" />
|
||||
<field name="day_qty" />
|
||||
<field name="price_unit" />
|
||||
<field
|
||||
@@ -43,6 +47,7 @@
|
||||
/>
|
||||
<field name="price_day_total" />
|
||||
<field name="is_board_service" invisible="1" />
|
||||
<field name="pms_property_id" invisible="1" />
|
||||
</tree>
|
||||
</field>
|
||||
</sheet>
|
||||
@@ -85,6 +90,8 @@
|
||||
attrs="{'readonly': [('per_day','=',True)]}"
|
||||
force_save="1"
|
||||
/>
|
||||
<field name="sale_channel_origin_id" />
|
||||
<field name="sale_channel_ids" />
|
||||
<button
|
||||
type="object"
|
||||
class="oe_stat_button"
|
||||
@@ -99,6 +106,7 @@
|
||||
<field name="service_line_ids" invisible="1">
|
||||
<tree string="Days">
|
||||
<field name="date" />
|
||||
<field name="sale_channel_id" />
|
||||
<field name="day_qty" />
|
||||
<field
|
||||
name="discount"
|
||||
@@ -106,6 +114,7 @@
|
||||
/>
|
||||
<field name="price_unit" />
|
||||
<field name="is_board_service" invisible="1" />
|
||||
<field name="pms_property_id" invisible="1" />
|
||||
</tree>
|
||||
</field>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user