Merge pull request #3196 from expsa/younes_dev_odex25_accounting

Add total amount for purchase request lines
This commit is contained in:
kchyounes19 2025-05-15 07:52:42 +01:00 committed by GitHub
commit ab5f00bd08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 6 deletions

View File

@ -162,6 +162,7 @@ msgid "This product has no expense account"
msgstr "هذا المنتج ليس له حساب مصروف"
#. module: initial_engagement_budget
#: model:ir.model.fields,field_description:initial_engagement_budget.field_purchase_request__total_amount
#: model:ir.model.fields,field_description:initial_engagement_budget.field_purchase_request_line__line_total
msgid "Total"
msgstr "إجمالي"

View File

@ -11,15 +11,24 @@ class PurchaseRequest(models.Model):
state = fields.Selection(
selection_add=[('wait_for_send', 'Wait For Sent'),
('initial', 'Initial Engagement')],
('initial', 'Initial Engagement')],
default="draft",
tracking=True
)
state_a = fields.Selection(related='state',tracking=False)
state_b = fields.Selection(related='state',tracking=False)
state_a = fields.Selection(related='state', tracking=False)
state_b = fields.Selection(related='state', tracking=False)
initial_engagement_activate = fields.Boolean(compute='_check_initial_engagement_activate', store=True,
default=False)
total_amount = fields.Monetary(string="Total", compute="_compute_total_amount",
currency_field='company_currency_id', store=True)
company_currency_id = fields.Many2one("res.currency", string="Currency", related="company_id.currency_id",
readonly=True)
@api.depends('line_ids', 'line_ids.line_total')
def _compute_total_amount(self):
for request in self:
request.total_amount = sum(line.line_total for line in request.line_ids)
def action_skip_budget(self):
self.state = 'waiting'
@ -66,11 +75,11 @@ class PurchaseRequest(models.Model):
raise ValidationError(
_("This product has no expense account") + ': {}'.format(rec.product_id.name))
budget_post = self.env['account.budget.post'].search([]).filtered(lambda x: account_id in x.account_ids)
budget_post = self.env['account.budget.post'].search([]).filtered(lambda x: account_id in x.account_ids)
if len(budget_post.ids) > 1:
raise ValidationError(
_("The Expense account %s is assigned to more than one budget position %s") % (
account_id.name, [x.name for x in budget_post]))
account_id.name, [x.name for x in budget_post]))
budget_lines = self.env['crossovered.budget.lines'].search(
[('analytic_account_id', '=', analytic_account.id),
('general_budget_id', 'in', budget_post.ids),
@ -123,7 +132,7 @@ class PurchaseRequest(models.Model):
'product_qty': line.qty,
'name': line.description or line.product_id.name,
'department_name': self.employee_id.department_id.id,
'account_analytic_id':analytic_account,
'account_analytic_id': analytic_account,
'date_planned': datetime.today(),
'price_unit': 0,
}))

View File

@ -38,6 +38,14 @@
<field name="line_total"
attrs="{'column_invisible': [('parent.initial_engagement_activate', '!=', True)]}"/>
</xpath>
<xpath expr="//page[@name='purchase_request_info']/field[@name='line_ids']" position="after">
<field name="company_currency_id" invisible="1"/>
<group class="oe_subtotal_footer oe_right">
<label for="total_amount"/>
<field name="total_amount" nolabel="1" widget="monetary"
options="{'currency_field': 'company_currency_id'}"/>
</group>
</xpath>
</field>
</record>
</odoo>