diff --git a/pms/models/account_move.py b/pms/models/account_move.py index 16c51fb65..3ff2e0ab8 100644 --- a/pms/models/account_move.py +++ b/pms/models/account_move.py @@ -37,6 +37,15 @@ class AccountMove(models.Model): related="journal_id.is_simplified_invoice", store=True, ) + origin_agency_id = fields.Many2one( + string="Origin Agency", + help="The agency where the folio account move originates", + comodel_name="res.partner", + domain="[('is_agency', '=', True)]", + compute="_compute_origin_agency_id", + store=True, + readonly=False, + ) @api.onchange("pms_property_id") def _onchange_pms_property_id(self): @@ -69,6 +78,19 @@ class AccountMove(models.Model): move.folio_ids = False move.folio_ids = move.mapped("line_ids.folio_ids.id") + @api.depends("line_ids", "line_ids.origin_agency_id") + def _compute_origin_agency_id(self): + """ + Compute the origin agency of the account move + if the move has multiple agencies in origin, + the first one is returned (REVIEW: is this correct?) + """ + self.origin_agency_id = False + for move in self: + agencies = move.mapped("line_ids.origin_agency_id") + if agencies: + move.origin_agency_id = agencies[0] + def _compute_payments_widget_to_reconcile_info(self): for move in self: if not move.line_ids.folio_line_ids: diff --git a/pms/models/account_move_line.py b/pms/models/account_move_line.py index aed425ca5..9fee23ccf 100644 --- a/pms/models/account_move_line.py +++ b/pms/models/account_move_line.py @@ -10,6 +10,11 @@ class AccountMoveLine(models.Model): # Fields declaration # TODO: REVIEW why not a Many2one? + name = fields.Char( + compute="_compute_name", + store=True, + readonly=False, + ) folio_line_ids = fields.Many2many( string="Folio Lines", help="The folio lines in the account move lines", @@ -41,47 +46,16 @@ class AccountMoveLine(models.Model): readonly=False, check_pms_properties=True, ) - move_id = fields.Many2one(check_pms_properties=True) - - @api.depends("move_id") - def _compute_pms_property_id(self): - for rec in self: - if rec.move_id and rec.move_id.pms_property_id: - rec.pms_property_id = rec.move_id.pms_property_id - 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 - - name = fields.Char( - compute="_compute_name", + origin_agency_id = fields.Many2one( + string="Origin Agency", + help="The agency where the folio account move originates", + comodel_name="res.partner", + domain="[('is_agency', '=', True)]", + compute="_compute_origin_agency_id", store=True, readonly=False, ) - - @api.depends( - "folio_line_ids", - "payment_id", - "payment_id.folio_ids", - "statement_line_id", - "statement_line_id.folio_ids", - ) - def _compute_folio_ids(self): - if self.folio_line_ids: - self.folio_ids = self.folio_line_ids.mapped("folio_id") - elif self.payment_id: - self.folio_ids = self.payment_id.folio_ids - elif self.statement_line_id: - self.folio_ids = self.statement_line_id.folio_ids - else: - self.folio_ids = False + move_id = fields.Many2one(check_pms_properties=True) @api.depends("quantity") def _compute_name(self): @@ -104,3 +78,51 @@ class AccountMoveLine(models.Model): # qty=record.quantity) # record.with_context(auto_name=True) # ._compute_name_changed_by_user() + + @api.depends("move_id") + def _compute_pms_property_id(self): + for rec in self: + if rec.move_id and rec.move_id.pms_property_id: + rec.pms_property_id = rec.move_id.pms_property_id + 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", + "payment_id.folio_ids", + "statement_line_id", + "statement_line_id.folio_ids", + ) + def _compute_folio_ids(self): + if self.folio_line_ids: + self.folio_ids = self.folio_line_ids.mapped("folio_id") + elif self.payment_id: + self.folio_ids = self.payment_id.folio_ids + elif self.statement_line_id: + self.folio_ids = self.statement_line_id.folio_ids + else: + self.folio_ids = False + + @api.depends("folio_line_ids") + def _compute_origin_agency_id(self): + """ + Compute the origin agency of the account move line, + if the line has multiple agencies in origin, + (p.e. nights with different agencies in origin), + the first one is returned (REVIEW: is this correct?) + """ + self.origin_agency_id = False + for line in self: + agencies = line.mapped("folio_line_ids.origin_agency_id") + if agencies: + line.origin_agency_id = agencies[0] diff --git a/pms/models/account_payment.py b/pms/models/account_payment.py index 1d72cb2e1..213f20fdd 100644 --- a/pms/models/account_payment.py +++ b/pms/models/account_payment.py @@ -17,6 +17,42 @@ class AccountPayment(models.Model): column1="payment_id", column2="folio_id", ) + origin_agency_id = fields.Many2one( + string="Origin Agency", + help="The agency where the folio account move originates", + comodel_name="res.partner", + domain="[('is_agency', '=', True)]", + compute="_compute_origin_agency_id", + store=True, + readonly=True, + ) + + @api.depends("reconciled_invoice_ids", "reconciled_bill_ids") + def _compute_origin_agency_id(self): + """ + Compute the origin agency of the sale line, + if the line has multiple agencies in origin, + (p.e. nights with different agencies in origin), + the first one is returned (REVIEW: is this correct?) + """ + for rec in self: + inv_agency_ids = rec.reconciled_invoice_ids.mapped( + "line_ids.folio_line_ids.origin_agency_id.id" + ) + bill_agency_ids = rec.reconciled_bill_ids.mapped( + "line_ids.folio_line_ids.origin_agency_id.id" + ) + agency_ids = list(set(inv_agency_ids + bill_agency_ids)) + if agency_ids: + rec.write({"origin_agency_id": agency_ids[0]}) + elif ( + not rec.reconciled_invoice_ids + and not rec.reconciled_bill_ids + and rec.folio_ids + ): + rec.origin_agency_id = rec.origin_agency_id + else: + rec.origin_agency_id = False @api.depends("reconciled_invoice_ids", "reconciled_bill_ids") def _compute_folio_ids(self): diff --git a/pms/models/folio_sale_line.py b/pms/models/folio_sale_line.py index 2161a6e10..becea0ffc 100644 --- a/pms/models/folio_sale_line.py +++ b/pms/models/folio_sale_line.py @@ -264,6 +264,15 @@ class FolioSaleLine(models.Model): store=True, related="folio_id.partner_id", ) + origin_agency_id = fields.Many2one( + string="Origin Agency", + help="The agency where the folio sale line originates", + comodel_name="res.partner", + domain="[('is_agency', '=', True)]", + compute="_compute_origin_agency_id", + store=True, + readonly=False, + ) analytic_tag_ids = fields.Many2many( string="Analytic Tags", comodel_name="account.analytic.tag", @@ -320,6 +329,14 @@ class FolioSaleLine(models.Model): compute="_compute_date_order", ) + @api.depends( + "reservation_line_ids", + "reservation_id.agency_id", + ) + def _compute_origin_agency_id(self): + for rec in self: + rec.origin_agency_id = rec.folio_id.agency_id + @api.depends("qty_to_invoice") def _compute_service_order(self): for record in self: diff --git a/pms/views/account_move_views.xml b/pms/views/account_move_views.xml index f7dad3bbf..770fafada 100644 --- a/pms/views/account_move_views.xml +++ b/pms/views/account_move_views.xml @@ -16,7 +16,9 @@ domain="[('company_id','=',company_id)]" /> - + + + + @@ -50,6 +53,11 @@ string="Property" context="{'group_by':'pms_property_id'}" /> + @@ -67,6 +75,11 @@ string="Property" context="{'group_by':'pms_property_id'}" /> + diff --git a/pms/views/account_payment_views.xml b/pms/views/account_payment_views.xml index 161f2b19f..dce771834 100644 --- a/pms/views/account_payment_views.xml +++ b/pms/views/account_payment_views.xml @@ -5,7 +5,50 @@ - + + + + + + + + account.payment + + + + + + + + + + + + account.payment + + + + + + + + +