Skip to content

Commit

Permalink
Use company currency by default in the wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
guewen committed May 29, 2017
1 parent 2b68d38 commit 323b6cd
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions sale_line_cost_control/wizards/set_sale_line_purchase_price.py
Expand Up @@ -14,6 +14,7 @@ class SetSaleLinePurchasePrice(models.TransientModel):
string='Sale Line',
readonly=True,
required=True,
default=lambda s: s._default_line_id()
)
purchase_price = fields.Float(
string='Cost',
Expand All @@ -26,8 +27,18 @@ class SetSaleLinePurchasePrice(models.TransientModel):
comodel_name='res.currency',
string="Currency",
required=True,
default=lambda s: s._default_currency_id()
)

def _default_line_id(self):
assert self.env.context['active_model'] == 'sale.order.line'
line_id = self.env.context.get('active_id')
return line_id

def _default_currency_id(self):
company = self.env.user.company_id
return company.currency_id.id

@api.multi
def confirm_purchase_price(self):
self.ensure_one()
Expand All @@ -38,16 +49,3 @@ def confirm_purchase_price(self):
cost = currency_at_date.compute(self.purchase_price,
company.currency_id)
self.line_id.purchase_price = cost

@api.model
def default_get(self, fields_list):
_super = super(SetSaleLinePurchasePrice, self)
values = _super.default_get(fields_list)
assert self.env.context['active_model'] == 'sale.order.line'
line_id = self.env.context.get('active_id')
line = self.env['sale.order.line'].browse(line_id)
values.update({
'line_id': line.id,
'currency_id': line.order_id.currency_id.id,
})
return values

0 comments on commit 323b6cd

Please sign in to comment.