Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
9051 Lượt xem

Hi,

I am working on create new Sale Order. 

When user selects a Customer, I would like to check the expiration date of Credit Limit of the selected customer.

If it invalid, display a warning popup with 2 buttons [Go to customer page|Cancel]

If user select 'Cancel', the pop up will close and user can do their job as usual.

Here is my source code

class CreditLimitWizard(models.TransientModel):
_name = 'sale.credit.limit.wizard'
_description = 'Sale Credit Limit Wizard'

name = fields.Char('Customer Name')
credit_limit = fields.Float('Credit Limit')
expire_date = fields.Date('Expire Date')
<record model="ir.ui.view" id="sale_credit_limit_wizard">
<field name="name">Customer Credit Limit Wizard</field>
<field name="model">sale.credit.limit.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form>
<group>
<span>The following customer is about or expired their credit limit:
</span>
</group>
<group>
<field name="name"/>
<field name="credit_limit" widget="monetary"/>
<field name="expire_date"/>
</group>
<footer>
<button string="Cancel" special="cancel" class="oe_highlight"/>
<!--<button name="go_customer" string="Go to customer page" type="object"-->
<!--class="oe_highlight"/>-->
</footer>
</form>
</field>
</record>
class SaleOrder(models.Model):
_inherit = 'sale.order'

@api.onchange('partner_id')
def _check_credit_limit_expired(self):
for order in self:
if order.partner_id and order.partner_id.credit_limit_expired:
expire_date = order.partner_id.credit_limit_expired
# Check expire date
if expire_date < fields.Date.today() + datetime.timedelta(days=-7):
view = self.env.ref('soj_credit.sale_credit_limit_wizard')
wiz = self.env['sale.credit.limit.wizard'].create({
'name': order.partner_id.name,
'credit_limit': order.partner_id.credit_limit,
'expire_date': expire_date.strftime('%Y-%m-%d'),
})
return {
'type': 'ir.actions.act_window',
'name': 'Warning : Customer is about or expired their credit limit',
'res_model': 'sale.credit.limit.wizard',
'view_type': 'form',
'view_mode': 'form',
'views': [(view.id, 'form')],
'view_id': view.id,
'res_id': wiz.id,
'target': 'new',
}

This code can check the expire date logic but it shows nothing on my browser.

Thank you for your help!





Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

i want to this code in POS.
can you explain step by step configuration and adding that code ?

i am new in odoo

thank you for your help.



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

I found the solution below

@api.onchange('partner_id')
def _onchange_partner(self):
if self.partner_id and self.partner_id.credit_limit_expired:
expire_date = self.partner_id.credit_limit_expired
title = _("Warning for %s") % self.partner_id.name

if expire_date < fields.Date.today() + datetime.timedelta(days=-7):
message = _(
"Credit limit setting was expired on %s. \n Please update their credit limit.\n") % expire_date.strftime(
'%Y-%m-%d')
warning = {
'title': title,
'message': message
}
return {'warning': warning}
return {}
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 24
1086
2
thg 9 23
12815
3
thg 7 21
13870
0
thg 6 19
7398
1
thg 5 25
884