mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: add origin agency in invoices and payments
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
domain="[('company_id','=',company_id)]"
|
||||
/>
|
||||
</xpath>
|
||||
|
||||
<xpath expr="//field[@name='invoice_user_id']" position="before">
|
||||
<field name="origin_agency_id" />
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='quantity']" position="before">
|
||||
<field name="name_changed_by_user" invisible="1" />
|
||||
<field
|
||||
@@ -33,6 +35,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='company_id']" position="after">
|
||||
<field name="pms_property_id" optional="show" />
|
||||
<field name="origin_agency_id" optional="show" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
@@ -50,6 +53,11 @@
|
||||
string="Property"
|
||||
context="{'group_by':'pms_property_id'}"
|
||||
/>
|
||||
<filter
|
||||
name="origin_agency_id"
|
||||
string="Originating agency"
|
||||
context="{'group_by':'origin_agency_id'}"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
@@ -67,6 +75,11 @@
|
||||
string="Property"
|
||||
context="{'group_by':'pms_property_id'}"
|
||||
/>
|
||||
<filter
|
||||
name="by_origin_agency"
|
||||
string="Originating agency"
|
||||
context="{'group_by':'origin_agency_id'}"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -5,7 +5,50 @@
|
||||
<field name="inherit_id" ref="account.view_account_payment_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='date']" position="after">
|
||||
<field name="folio_ids" />
|
||||
<field
|
||||
name="folio_ids"
|
||||
widget="many2many_tags"
|
||||
attrs="{'invisible':[('partner_type','!=','customer')]}"
|
||||
/>
|
||||
<field
|
||||
name="origin_agency_id"
|
||||
attrs="{'invisible':[('origin_agency_id','=',False)]}"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_account_payment_tree" model="ir.ui.view">
|
||||
<field name="model">account.payment</field>
|
||||
<field name="inherit_id" ref="account.view_account_payment_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='company_id']" position="before">
|
||||
<field name="folio_ids" optional="hidden" />
|
||||
<field name="pms_property_id" optional="hidden" />
|
||||
<field name="origin_agency_id" optional="hidden" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_account_payment_search" model="ir.ui.view">
|
||||
<field name="model">account.payment</field>
|
||||
<field name="inherit_id" ref="account.view_account_payment_search" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='journal_id']" position="after">
|
||||
<field name="pms_property_id" />
|
||||
<field name="origin_agency_id" />
|
||||
</xpath>
|
||||
<xpath expr="//filter[@name='company']" position="after">
|
||||
<filter
|
||||
name="by_property"
|
||||
string="Property"
|
||||
context="{'group_by':'pms_property_id'}"
|
||||
/>
|
||||
<filter
|
||||
name="by_origin_agency"
|
||||
string="Originating agency"
|
||||
context="{'group_by':'origin_agency_id'}"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user