[IMP] sale: default advance product in res.config
Instead of using the demo data, it is now possible to set up a defaut product for payment advances.
This commit is contained in:
@@ -64,7 +64,10 @@ class sale_configuration(osv.TransientModel):
|
||||
('order', 'Invoice ordered quantities'),
|
||||
('delivery', 'Invoice delivered quantities'),
|
||||
('cost', 'Invoice based on costs (time and material, expenses)')
|
||||
], 'Default Invoicing', default_model='product.template')
|
||||
], 'Default Invoicing', default_model='product.template'),
|
||||
'deposit_product_id_setting': fields.many2one('product.product', 'Default Advance Product',\
|
||||
domain="[('type', '=', 'service')]",\
|
||||
help='Default product used for payment advances'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
@@ -77,6 +80,11 @@ class sale_configuration(osv.TransientModel):
|
||||
res = self.pool.get('ir.values').set_default(cr, uid, 'sale.config.settings', 'sale_pricelist_setting', sale_price)
|
||||
return res
|
||||
|
||||
def set_deposit_product_id_defaults(self, cr, uid, ids, context=None):
|
||||
deposit_product_id = self.browse(cr, uid, ids, context=context).deposit_product_id_setting
|
||||
res = self.pool.get('ir.values').set_default(cr, uid, 'sale.config.settings', 'deposit_product_id_setting', deposit_product_id.id)
|
||||
return res
|
||||
|
||||
def onchange_sale_price(self, cr, uid, ids, sale_pricelist_setting, context=None):
|
||||
if sale_pricelist_setting == 'percentage':
|
||||
return {'value': {'group_product_pricelist': True, 'group_sale_pricelist': True, 'group_pricelist_item': False}}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<field name="module_website_sale_digital" widget="radio"/>
|
||||
<field name="group_uom" widget="radio"/>
|
||||
<field name="default_invoice_policy" widget="radio"/>
|
||||
<field name="deposit_product_id_setting" class="oe_inline"/>
|
||||
</group>
|
||||
<group string="Quotations & Sales" id="sale">
|
||||
<field name="group_sale_delivery_address" widget="radio"/>
|
||||
|
||||
@@ -48,7 +48,7 @@ class TestSale(TestMail):
|
||||
'email': 'testcustomer@test.com',
|
||||
'property_account_receivable_id': account_recv_id,
|
||||
})
|
||||
|
||||
|
||||
# In order to test I create sale order and confirmed it.
|
||||
order = self.env['sale.order'].create({
|
||||
'partner_id': partner.id,
|
||||
@@ -60,7 +60,11 @@ class TestSale(TestMail):
|
||||
context = {"active_model": 'sale.order', "active_ids": [order.id], "active_id": order.id}
|
||||
order.with_context(context).action_confirm()
|
||||
# Now I create invoice.
|
||||
payment = self.env['sale.advance.payment.inv'].create({'advance_payment_method': 'fixed', 'amount': 5})
|
||||
payment = self.env['sale.advance.payment.inv'].create({
|
||||
'advance_payment_method': 'fixed',
|
||||
'amount': 5,
|
||||
'product_id': self.env.ref('sale.advance_product_0').id,
|
||||
})
|
||||
invoice = payment.with_context(context).create_invoices()
|
||||
assert order.invoice_ids, "No any invoice is created for this sale order"
|
||||
# Now I validate pay invoice wihth Test User(invoicing and payment).
|
||||
|
||||
@@ -23,20 +23,14 @@ class SaleAdvancePaymentInv(models.TransientModel):
|
||||
return 'all'
|
||||
return 'delivered'
|
||||
|
||||
@api.model
|
||||
def _get_advance_product(self):
|
||||
try:
|
||||
return self.env['ir.model.data'].xmlid_to_res_id('sale.advance_product_0', raise_if_not_found=True)
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
advance_payment_method = fields.Selection([
|
||||
('all', 'Invoiceable lines (deduce deposits)'),
|
||||
('delivered', 'Invoiceable lines'),
|
||||
('percentage', 'Deposit (percentage)'),
|
||||
('fixed', 'Deposit (fixed amount)')
|
||||
], string='What do you want to invoice?', default=_get_advance_payment_method, required=True)
|
||||
product_id = fields.Many2one('product.product', string='Deposit Product', domain=[('type', '=', 'service')], default=_get_advance_product)
|
||||
product_id = fields.Many2one('product.product', string='Deposit Product', domain=[('type', '=', 'service')],\
|
||||
default=lambda self: self.env['ir.values'].get_default('sale.config.settings', 'deposit_product_id_setting'))
|
||||
count = fields.Integer(default=_count, string='# of Orders')
|
||||
amount = fields.Float('Deposit Amount', digits=dp.get_precision('Account'), help="The amount to be invoiced in advance, taxes excluded.")
|
||||
|
||||
|
||||
@@ -82,7 +82,8 @@ class TestSaleStock(TestSale):
|
||||
# let's do an invoice for a deposit of 5%
|
||||
adv_wiz = self.env['sale.advance.payment.inv'].with_context(active_ids=[self.so.id]).create({
|
||||
'advance_payment_method': 'percentage',
|
||||
'amount': 5.0
|
||||
'amount': 5.0,
|
||||
'product_id': self.env.ref('sale.advance_product_0').id,
|
||||
})
|
||||
act = adv_wiz.with_context(open_invoices=True).create_invoices()
|
||||
inv = self.env['account.invoice'].browse(act['res_id'])
|
||||
|
||||
Reference in New Issue
Block a user