Skip to content

Commit

Permalink
[IMP]pms: invoice line name automatic control
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioLodeiros committed Apr 17, 2022
1 parent eb231a8 commit b6e0c97
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
47 changes: 15 additions & 32 deletions pms/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class AccountMoveLine(models.Model):
check_pms_properties=True,
)
name_changed_by_user = fields.Boolean(
string="Custom label",
readonly=False,
default=False,
store=True,
compute="_compute_name_changed_by_user",
string="Name set manually",
help="""Techinal field to know if the name was set manually by the user
or by the system. If the name was set manually, the system will not
change it when the qty days are changed""",
default=True,
)
pms_property_id = fields.Many2one(
name="Property",
Expand All @@ -60,24 +60,16 @@ class AccountMoveLine(models.Model):
@api.depends("quantity")
def _compute_name(self):
for record in self:
record.name = self.env["folio.sale.line"].generate_folio_sale_name(
record.folio_line_ids.reservation_id,
record.product_id,
record.folio_line_ids.service_id,
record.folio_line_ids.reservation_line_ids,
record.folio_line_ids.service_line_ids,
qty=record.quantity,
)
# TODO: check why this code doesn't work
# if not record.name_changed_by_user:
# record.with_context(auto_name=True).name = self
# .env["folio.sale.line"].generate_folio_sale_name(
# record.folio_line_ids.service_id,
# record.folio_line_ids.reservation_line_ids,
# record.product_id,
# qty=record.quantity)
# record.with_context(auto_name=True)
# ._compute_name_changed_by_user()
if record.folio_line_ids and not record.name_changed_by_user:
record.name_changed_by_user = False
record.name = self.env["folio.sale.line"].generate_folio_sale_name(
record.folio_line_ids.reservation_id,
record.product_id,
record.folio_line_ids.service_id,
record.folio_line_ids.reservation_line_ids,
record.folio_line_ids.service_line_ids,
qty=record.quantity,
)

@api.depends("move_id")
def _compute_pms_property_id(self):
Expand All @@ -87,15 +79,6 @@ def _compute_pms_property_id(self):
elif not rec.pms_property_id:
rec.pms_property_id = False

@api.depends("name")
def _compute_name_changed_by_user(self):
for record in self:
# if not record._context.get("auto_name"):
if not self._context.get("auto_name"):
record.name_changed_by_user = True
else:
record.name_changed_by_user = False

@api.depends(
"folio_line_ids",
"payment_id",
Expand Down
1 change: 1 addition & 0 deletions pms/models/folio_sale_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ def _prepare_invoice_line(self, qty=False, **optional_values):
"analytic_account_id": self.folio_id.analytic_account_id.id,
"analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)],
"folio_line_ids": [(6, 0, [self.id])],
"name_changed_by_user": False,
}
if optional_values:
res.update(optional_values)
Expand Down
2 changes: 1 addition & 1 deletion pms/models/pms_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ def _create_account_moves(self, invoice_vals_list):
move = (
self.env["account.move"]
.sudo()
.with_context(default_move_type="out_invoice", auto_name=True)
.with_context(default_move_type="out_invoice")
.create(invoice_vals)
)
moves += move
Expand Down
2 changes: 1 addition & 1 deletion pms/views/account_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
expr="//field[@name='invoice_line_ids']/tree/field[@name='quantity']"
position="before"
>
<field name="name_changed_by_user" invisible="1" />
<field name="name_changed_by_user" invisible="0" />
<field
name="pms_property_id"
attrs="{'column_invisible':[('parent.pms_property_id','!=',False)]}"
Expand Down

0 comments on commit b6e0c97

Please sign in to comment.