Skip to content

Commit

Permalink
Merge pull request #1869 from floraXiao/master
Browse files Browse the repository at this point in the history
[FIX]sell_to_buy:购货订单行增加sell_line_id,删除时去掉对应销货单行的已采购打勾 #1857
  • Loading branch information
floraXiao committed Jul 9, 2018
2 parents 4ab18de + 3f9f886 commit 7d7da02
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
2 changes: 2 additions & 0 deletions asset/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ def asset_draft(self):
raise UserError(u'已变更不能撤销确认!')
if self.period_id.is_closed:
raise UserError(u'该会计期间(%s)已结账!不能撤销确认' % self.period_id.name)
if self.money_invoice.reconciled != 0:
raise UserError(u'固定资产已有核销,请不要撤销')

'''删掉凭证'''
if self.voucher_id:
Expand Down
6 changes: 3 additions & 3 deletions money/models/money_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ def onchange_partner_id(self):

for invoice in self.env['money.invoice'].search(self._get_invoice_search_list()):
source_lines.append(self._get_source_line(invoice))
if source_lines:
self.source_ids = source_lines
self.source_ids = source_lines

@api.multi
def money_order_done(self):
Expand Down Expand Up @@ -1137,7 +1136,8 @@ def _get_or_pay_cancel(self, line, business_type, name):
if business_type in ['get_to_get', 'pay_to_pay']:
invoices = self.env['money.invoice'].search([('name', '=', name)])
for inv in invoices:
inv.money_invoice_draft()
if inv.state == 'done':
inv.money_invoice_draft()
inv.unlink()
return True

Expand Down
23 changes: 17 additions & 6 deletions sell_to_buy/models/buy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

from odoo import models, fields, api

# 字段只读状态
READONLY_STATES = {
'done': [('readonly', True)],
}


class buy_order(models.Model):
_inherit = "buy.order"

sell_id = fields.Many2one('sell.order', u'销货订单', index=True,
states=READONLY_STATES,
readonly=True,
ondelete='restrict',
help=u'关联的销货订单')

Expand All @@ -27,3 +22,19 @@ def sell_to_buy(self):
'type': 'ir.actions.act_window',
'target': 'new',
}


class buy_order_line(models.Model):
_inherit = "buy.order.line"

sell_line_id = fields.Many2one('sell.order.line',
u'销货单行',
ondelete='restrict',
help=u'对应的销货订单行')

@api.multi
def unlink(self):
'''删除购货订单行时,如果对应销货订单行已采购,则去掉打勾'''
for line in self:
line.sell_line_id.is_bought = False
return super(buy_order_line, self).unlink()
3 changes: 0 additions & 3 deletions sell_to_buy/models/sell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@
class sell_order_line(models.Model):
_inherit = "sell.order.line"

buy_line_id = fields.Many2one('buy.order.line',
u'购货单行',
help=u'对应的购货订单行')
is_bought = fields.Boolean(u'已采购')
4 changes: 3 additions & 1 deletion sell_to_buy/views/buy_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<field name="currency_id" position="after">
<field name="sell_id"/>
</field>
<field name="using_attribute" position="after">
<field name="sell_line_id" invisible="1"/>
</field>
</field>
</record>
<record id="sell_order_form_inherit" model="ir.ui.view">
Expand All @@ -20,7 +23,6 @@
<field name='inherit_id' ref='sell.sell_order_form' />
<field name="arch" type="xml">
<field name="using_attribute" position="after" >
<field name="buy_line_id" invisible="1"/>
<field name="is_bought" invisible="1"/>
</field>
</field>
Expand Down
2 changes: 1 addition & 1 deletion sell_to_buy/wizard/sell_to_buy_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _get_vals(self, order, line):
'discount_amount': line.discount_amount,
'tax_rate': line.tax_rate,
'note': line.note or '',
'sell_line_id': line.id, # sell_line_id写入到购货订单行上
}

@api.multi
Expand All @@ -52,7 +53,6 @@ def button_ok(self):
for line in wizard.sell_line_ids:
buy_lines.append(self._get_vals(order, line))
line.is_bought = True
# fixme:buy_line_id写入到销货订单行上
# 将销货订单行复制到购货订单
order.write({
'sell_id': order_dict.keys()[0].id,
Expand Down
2 changes: 1 addition & 1 deletion sell_to_buy/wizard/sell_to_buy_wizard_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<group>
<group>
<field name='sell_line_ids'
domain="[(('is_bought', '=', False))]"
domain="[('is_bought', '=', False), ('order_id.type', '=', 'sell')]"
context="{'search_default_group_by_order': 1,
'tree_view_ref': 'sell_to_buy.sell_order_line_tree'}"
/>
Expand Down

0 comments on commit 7d7da02

Please sign in to comment.