Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions subscription_oca/models/sale_order_line.py
Copy link
Copy Markdown

@rrebollo rrebollo Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't You forcing an analytic distribution even if there wasn't one in the source sale.order.line? Pardon my ignorance. Would you be so kind to explain me the use case?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked something similar it's done in built-in sale_order addon in order to prepare invoice lines but: is this really analogue ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method get_subscription_line_values is called to create a new subscription when sold (from sale.order): if sale.order.line has got an analytic_distribution then set it in subscription line, otherwise use the analytic account of Generated Project

Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ def get_subscription_line_values(self):
"price_unit": self.price_unit,
"discount": self.discount,
"price_subtotal": self.price_subtotal,
"analytic_distribution": self.analytic_distribution,
}
3 changes: 3 additions & 0 deletions subscription_oca/models/sale_subscription_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class SaleSubscriptionLine(models.Model):
_name = "sale.subscription.line"
_inherit = "analytic.mixin"
_description = "Subscription lines added to a given subscription"

product_id = fields.Many2one(
Expand Down Expand Up @@ -298,6 +299,7 @@ def _prepare_sale_order_line(self):
"price_subtotal": self.price_subtotal,
"tax_id": self.tax_ids,
"product_uom": self.product_id.uom_id.id,
"analytic_distribution": self.analytic_distribution,
}

def _prepare_account_move_line(self):
Expand All @@ -316,4 +318,5 @@ def _prepare_account_move_line(self):
"tax_ids": [(6, 0, self.tax_ids.ids)],
"product_uom_id": self.product_id.uom_id.id,
"account_id": account.id,
"analytic_distribution": self.analytic_distribution,
}
7 changes: 7 additions & 0 deletions subscription_oca/views/sale_subscription_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@
required="True"
widget="section_and_note_text"
/>
<field
name="analytic_distribution"
widget="analytic_distribution"
optional="hide"
groups="analytic.group_analytic_accounting"
options="{'product_field': 'product_id', 'business_domain': 'sale_order'}"
/>
<field name="currency_id" invisible="1" />
<field name="product_uom_qty" required="True" />
<field name="price_unit" required="True" />
Expand Down