Skip to content

Commit

Permalink
Merge PR #78 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by andhit-r
  • Loading branch information
ssi-bot committed Mar 30, 2024
2 parents 83e3323 + b71f681 commit 02731db
Show file tree
Hide file tree
Showing 17 changed files with 361 additions and 38 deletions.
2 changes: 2 additions & 0 deletions ssi_hr_cash_advance/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"ssi_transaction_open_mixin",
"ssi_transaction_done_mixin",
"ssi_transaction_cancel_mixin",
"ssi_transaction_pricelist_mixin",
"ssi_employee_document_mixin",
"ssi_product_line_account_mixin",
"ssi_company_currency_mixin",
"ssi_m2o_configurator_mixin",
"base_duration",
"base_automation",
],
Expand Down
35 changes: 35 additions & 0 deletions ssi_hr_cash_advance/models/hr_cash_advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class HrCashAdvance(models.Model):
"mixin.transaction_done",
"mixin.transaction_open",
"mixin.transaction_confirm",
"mixin.transaction_pricelist",
"mixin.many2one_configurator",
"mixin.employee_document",
"mixin.company_currency",
]
Expand Down Expand Up @@ -109,6 +111,9 @@ class HrCashAdvance(models.Model):
],
},
)
pricelist_id = fields.Many2one(
required=False,
)
allowed_product_ids = fields.Many2many(
string="Allowed Product",
comodel_name="product.product",
Expand All @@ -127,6 +132,12 @@ class HrCashAdvance(models.Model):
related="type_id.allowed_product_usage_ids",
store=False,
)
allowed_pricelist_ids = fields.Many2many(
string="Allowed Pricelists",
comodel_name="product.pricelist",
compute="_compute_allowed_pricelist_ids",
store=False,
)

@api.model
def _default_currency_id(self):
Expand Down Expand Up @@ -341,6 +352,22 @@ def _compute_allowed_analytic_account_ids(self):
store=False,
)

@api.depends("type_id", "currency_id", "employee_id")
def _compute_allowed_pricelist_ids(self):
for record in self:
result = False
if record.type_id and record.currency_id and record.employee_id:
result = record._m2o_configurator_get_filter(
object_name="product.pricelist",
method_selection=record.type_id.pricelist_selection_method,
manual_recordset=record.type_id.pricelist_ids,
domain=record.type_id.pricelist_domain,
python_code=record.type_id.pricelist_python_code,
)
record.allowed_pricelist_ids = result.filtered(
lambda r: r.currency_id.id == record.currency_id.id
)

@api.model
def _get_policy_field(self):
res = super(HrCashAdvance, self)._get_policy_field()
Expand Down Expand Up @@ -552,6 +579,14 @@ def onchange_line_analytic_account_id(self):
if self.type_id:
self.line_ids.analytic_account_id = False

@api.onchange(
"employee_id",
"type_id",
"currency_id",
)
def onchange_pricelist_id(self):
self.pricelist_id = False

@ssi_decorator.insert_on_form_view()
def _insert_form_element(self, view_arch):
if self._automatically_insert_view_element:
Expand Down
4 changes: 4 additions & 0 deletions ssi_hr_cash_advance/models/hr_cash_advance_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class HrCashAdvanceLine(models.Model):
required=True,
ondelete="cascade",
)
pricelist_id = fields.Many2one(
related="cash_advance_id.pricelist_id",
store=True,
)
type_id = fields.Many2one(string="Type", related="cash_advance_id.type_id")
product_id = fields.Many2one(
required=True,
Expand Down
37 changes: 36 additions & 1 deletion ssi_hr_cash_advance/models/hr_cash_advance_settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class HrCashAdvanceSettlement(models.Model):
"mixin.transaction_cancel",
"mixin.transaction_done",
"mixin.transaction_confirm",
"mixin.transaction_pricelist",
"mixin.many2one_configurator",
"mixin.employee_document",
"mixin.company_currency",
]
Expand Down Expand Up @@ -85,6 +87,9 @@ class HrCashAdvanceSettlement(models.Model):
],
},
)
pricelist_id = fields.Many2one(
required=False,
)
allowed_product_ids = fields.Many2many(
string="Allowed Product",
comodel_name="product.product",
Expand All @@ -103,6 +108,12 @@ class HrCashAdvanceSettlement(models.Model):
related="type_id.allowed_product_usage_ids",
store=False,
)
allowed_pricelist_ids = fields.Many2many(
string="Allowed Pricelists",
comodel_name="product.pricelist",
compute="_compute_allowed_pricelist_ids",
store=False,
)

@api.model
def _default_currency_id(self):
Expand Down Expand Up @@ -241,6 +252,22 @@ def _compute_allowed_analytic_account_ids(self):
store=False,
)

@api.depends("type_id", "currency_id", "employee_id")
def _compute_allowed_pricelist_ids(self):
for record in self:
result = False
if record.type_id and record.currency_id and record.employee_id:
result = record._m2o_configurator_get_filter(
object_name="product.pricelist",
method_selection=record.type_id.pricelist_selection_method,
manual_recordset=record.type_id.pricelist_ids,
domain=record.type_id.pricelist_domain,
python_code=record.type_id.pricelist_python_code,
)
record.allowed_pricelist_ids = result.filtered(
lambda r: r.currency_id.id == record.currency_id.id
)

@api.model
def _get_policy_field(self):
res = super(HrCashAdvanceSettlement, self)._get_policy_field()
Expand Down Expand Up @@ -406,14 +433,22 @@ def onchange_line_analytic_account_id(self):
if self.type_id:
self.line_ids.analytic_account_id = False

@api.onchange(
"employee_id",
"type_id",
"currency_id",
)
def onchange_pricelist_id(self):
self.pricelist_id = False

@ssi_decorator.insert_on_form_view()
def _insert_form_element(self, view_arch):
if self._automatically_insert_view_element:
view_arch = self._reconfigure_statusbar_visible(view_arch)
return view_arch

def action_reload_cash_advance(self):
for rec in self.filtered(lambda s: s.state == "draft"):
for rec in self.sudo().filtered(lambda s: s.state == "draft"):
rec.line_ids = False
line_vals = []
for line_id in rec.cash_advance_id.line_ids:
Expand Down
4 changes: 4 additions & 0 deletions ssi_hr_cash_advance/models/hr_cash_advance_settlement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class HrCashAdvanceSettlementLine(models.Model):
required=True,
ondelete="cascade",
)
pricelist_id = fields.Many2one(
related="cash_advance_settlement_id.pricelist_id",
store=True,
)
type_id = fields.Many2one(
string="Type", related="cash_advance_settlement_id.type_id"
)
Expand Down
76 changes: 65 additions & 11 deletions ssi_hr_cash_advance/views/hr_cash_advance_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@
widget="many2many_tags"
invisible="1"
/>
<field
name="allowed_pricelist_ids"
widget="many2many_tags"
invisible="1"
/>
<field
name="pricelist_id"
domain="[('id', 'in', allowed_pricelist_ids)]"
/>
<field name="date" />
<field name="duration_id" />
<field name="date_due" />
Expand All @@ -164,30 +173,75 @@
<page name="detail" string="Details">
<field
name="line_ids"
context="{'default_currency_id': currency_id}"
context="{'default_currency_id': currency_id, 'default_pricelist_id': pricelist_id}"
>
<tree editable="top">
<tree>
<field name="currency_id" invisible="1" />
<field name="date_expense" />
<field
name="product_id"
domain="['|',('id','in',parent.allowed_product_ids),('categ_id','in',parent.allowed_product_category_ids)]"
/>
<field
name="usage_id"
domain="[('id','in',parent.allowed_product_usage_ids)]"
/>
<field name="account_id" />
<field name="product_id" />
<field name="usage_id" optional="hide" />
<field name="type_id" invisible="1" />
<field name="account_id" optional="hide" />
<field name="name" />
<field
name="analytic_account_id"
domain="[('id', 'in', parent.allowed_analytic_account_ids)]"
optional="show"
/>
<field name="price_unit" />
<field name="uom_quantity" />
<field name="uom_id" />
<field name="price_subtotal" />
</tree>
<form>
<field name="currency_id" invisible="1" />
<field name="type_id" invisible="1" />
<field
name="allowed_uom_ids"
widget="many2many_tags"
invisible="1"
/>
<group name="detail_1" colspan="4" col="2">
<group name="detail_1_1" colspan="1" col="2">
<field name="date_expense" />
<field
name="product_id"
domain="['|',('id','in',parent.allowed_product_ids),('categ_id','in',parent.allowed_product_category_ids)]"
/>
<field name="name" />
<field
name="usage_id"
domain="[('id','in',parent.allowed_product_usage_ids)]"
/>
<field name="account_id" />
<field
name="analytic_account_id"
domain="[('id', 'in', parent.allowed_analytic_account_ids)]"
/>
</group>
<group name="detail_1_1" colspan="1" col="2">
<field name="pricelist_id" />
<label for="uom_quantity" />
<div>
<field name="uom_quantity" />
<field
name="uom_id"
domain="[('id','in',allowed_uom_ids)]"
attrs="{'required':[('product_id','!=',False)]}"
class="oe_inline"
/>
</div>
<field name="quantity" invisible="1" />
<field name="price_unit" />
<field name="price_subtotal" />
</group>
</group>
<notebook>
<page name="note" string="Notes">
<field name="note" />
</page>
</notebook>
</form>
</field>
<group class="oe_subtotal_footer oe_right">

Expand Down
77 changes: 66 additions & 11 deletions ssi_hr_cash_advance/views/hr_cash_advance_views_settlement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@
name="cash_advance_id"
domain="[('id','in',allowed_cash_advance_ids)]"
/>
<field
name="allowed_pricelist_ids"
widget="many2many_tags"
invisible="1"
/>
<field
name="pricelist_id"
domain="[('id', 'in', allowed_pricelist_ids)]"
/>
<field name="date" />
</xpath>
<xpath expr="//page[1]" position="before">
Expand All @@ -161,34 +170,80 @@
type="object"
string="Reload from Cash Advance"
icon="fa-refresh text-primary"
class="oe_highlight"
states="draft"
/>
<field
name="line_ids"
context="{'default_currency_id': company_currency_id}"
context="{'default_currency_id': currency_id, 'default_pricelist_id': pricelist_id}"
>
<tree editable="top">
<tree>
<field name="currency_id" invisible="1" />
<field name="date_expense" />
<field
name="product_id"
domain="['|',('id','in',parent.allowed_product_ids),('categ_id','in',parent.allowed_product_category_ids)]"
/>
<field
name="usage_id"
domain="[('id','in',parent.allowed_product_usage_ids)]"
/>
<field name="account_id" />
<field name="product_id" />
<field name="usage_id" optional="hide" />
<field name="type_id" invisible="1" />
<field name="account_id" optional="hide" />
<field name="name" />
<field
name="analytic_account_id"
domain="[('id', 'in', parent.allowed_analytic_account_ids)]"
optional="show"
/>
<field name="price_unit" />
<field name="uom_quantity" />
<field name="uom_id" />
<field name="price_subtotal" />
</tree>
<form>
<field name="currency_id" invisible="1" />
<field name="type_id" invisible="1" />
<field
name="allowed_uom_ids"
widget="many2many_tags"
invisible="1"
/>
<group name="detail_1" colspan="4" col="2">
<group name="detail_1_1" colspan="1" col="2">
<field name="date_expense" />
<field
name="product_id"
domain="['|',('id','in',parent.allowed_product_ids),('categ_id','in',parent.allowed_product_category_ids)]"
/>
<field name="name" />
<field
name="usage_id"
domain="[('id','in',parent.allowed_product_usage_ids)]"
/>
<field name="account_id" />
<field
name="analytic_account_id"
domain="[('id', 'in', parent.allowed_analytic_account_ids)]"
/>
</group>
<group name="detail_1_1" colspan="1" col="2">
<field name="pricelist_id" />
<label for="uom_quantity" />
<div>
<field name="uom_quantity" />
<field
name="uom_id"
domain="[('id','in',allowed_uom_ids)]"
attrs="{'required':[('product_id','!=',False)]}"
class="oe_inline"
/>
</div>
<field name="quantity" invisible="1" />
<field name="price_unit" />
<field name="price_subtotal" />
</group>
</group>
<notebook>
<page name="note" string="Notes">
<field name="note" />
</page>
</notebook>
</form>
</field>
<group class="oe_subtotal_footer oe_right">
<field name="amount_total" string="Total" />
Expand Down
Loading

0 comments on commit 02731db

Please sign in to comment.